How to resolve the algorithm Rosetta Code/Count examples step by step in the Nim programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Rosetta Code/Count examples step by step in the Nim 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 Nim programming language
Source code in the nim programming language
import httpclient, strutils, xmltree, xmlparser, cgi
proc count(s, sub: string): int =
var i = 0
while true:
i = s.find(sub, i)
if i < 0: break
inc i
inc result
const
mainSite = "http://www.rosettacode.org/mw/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml"
subSite = "http://www.rosettacode.org/mw/index.php?title=$#&action=raw"
var client = newHttpClient()
var sum = 0
for node in client.getContent(mainSite).parseXml().findAll("cm"):
let t = node.attr("title").replace(" ", "_")
let c = client.getContent(subSite % encodeUrl(t)).toLower().count("header")
echo t.replace("_", " "), ": ", c, " examples."
inc sum, c
echo "\nTotal: ", sum, " examples."
You may also check:How to resolve the algorithm Binary digits step by step in the 8080 Assembly programming language
You may also check:How to resolve the algorithm Old lady swallowed a fly step by step in the Haskell programming language
You may also check:How to resolve the algorithm Runge-Kutta method step by step in the 11l programming language
You may also check:How to resolve the algorithm Dynamic variable names step by step in the RLaB programming language
You may also check:How to resolve the algorithm Create an HTML table step by step in the COBOL programming language