How to resolve the algorithm Rosetta Code/Count examples step by step in the Racket programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Rosetta Code/Count examples step by step in the Racket programming language
Table of Contents
Problem Statement
Essentially, count the number of occurrences of ==header on each task page. Output: For a full output, updated periodically, see Rosetta Code/Count examples/Full list. You'll need to use the Media Wiki API, which you can find out about locally, here, or in Media Wiki's API documentation at, API:Query
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Rosetta Code/Count examples step by step in the Racket programming language
Source code in the racket programming language
#lang racket
(require net/url net/uri-codec json (only-in racket/dict [dict-ref ref]))
(define (RC-get verb params)
((compose1 get-pure-port string->url format)
"http://rosettacode.org/mw/~a.php?~a" verb (alist->form-urlencoded params)))
(define (get-category catname)
(let loop ([c #f])
(define t
((compose1 read-json RC-get) 'api
`([action . "query"] [format . "json"]
[list . "categorymembers"] [cmtitle . ,(format "Category:~a" catname)]
[cmcontinue . ,(and c (ref c 'cmcontinue))] [cmlimit . "500"])))
(define (c-m key) (ref (ref t key '()) 'categorymembers #f))
(append (for/list ([page (c-m 'query)]) (ref page 'title))
(cond [(c-m 'query-continue) => loop] [else '()]))))
(printf "Total: ~a\n"
(for/sum ([task (get-category 'Programming_Tasks)])
(define s ((compose1 length regexp-match-positions*)
#rx"=={{" (RC-get 'index `([action . "raw"] [title . ,task]))))
(printf "~a: ~a\n" task s)
s))
You may also check:How to resolve the algorithm Mind boggling card trick step by step in the C programming language
You may also check:How to resolve the algorithm Roman numerals/Decode step by step in the Factor programming language
You may also check:How to resolve the algorithm Unicode variable names step by step in the Bracmat programming language
You may also check:How to resolve the algorithm Substring step by step in the AArch64 Assembly programming language
You may also check:How to resolve the algorithm Longest common subsequence step by step in the BASIC programming language