Rosetta Code/Count examples: Difference between revisions

Changed code to use "xmltree" and "xmlparser" as DOM modules are no longer provided. Changed the old URL by the right one.
(Changed code to use "xmltree" and "xmlparser" as DOM modules are no longer provided. Changed the old URL by the right one.)
Line 1,524:
 
=={{header|Nim}}==
<lang nim>import httpclient, strutils, xmldomxmltree, xmldomparserxmlparser, cgi
 
proc count(s, sub: string): int =
var i = 0
while true:
i = s.find(sub, i)
if i < 0: break
break
inc i
inc result
 
const
mainSite = "http://www.rosettacode.org/wmw/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml"
subSite = "http://www.rosettacode.org/wmw/index.php?title=$#&action=raw"
 
var client = newHttpClient()
var sum = 0
for inode in client.getContent(mainSite).loadXMLparseXml().getElementsByTagNamefindAll("cm"):
let t = PElement(i)node.getAttributeattr("title").replace(" ", "_")
let c = client.getContent(subSite % encodeUrl(t)).toLower().count("{{header|")
echo t.replace("_", " "), ": ", c, " examples."
suminc +=sum, c
 
echo "\nTotal: ", sum, " examples."</lang>
for i in getContent(mainSite).loadXML().getElementsByTagName("cm"):
let t = PElement(i).getAttribute("title").replace(" ", "_")
let c = getContent(subSite % encodeUrl(t)).toLower().count("{{header|")
echo t.replace("_", " "),": ",c," examples."
sum += c
 
{{out}}
echo "\nTotal: ",sum," examples."</lang>
<pre>100 doors: 326 examples.
Output:
<pre>100 doorsprisoners: 19455 examples.
2415 puzzle game: 6871 examples.
2415 game/Solvepuzzle solver: 4018 examples.
9 billion names of God the integer2048: 2057 examples.
9921 Bottles of Beergame: 22537 examples.
A+B24 game: 159100 examples.
ABC24 Problemgame/Solve: 4264 examples.
Abstract4-rings typeor 4-squares puzzle: 6057 examples.
Accumulator9 factorybillion names of God the integer: 7860 examples.
Ackermann99 functionbottles of beer: 151347 examples.
Active Directory/ConnectA+B: 16278 examples.
Abbreviations, automatic: 39 examples.
Abbreviations, easy: 38 examples.
Abbreviations, simple: 36 examples.
ABC problem: 132 examples.
Abelian sandpile model: 25 examples.
Abelian sandpile model/Identity: 19 examples.
Abstract type: 89 examples.
Abundant odd numbers: 53 examples.
Abundant, deficient and perfect number classifications: 89 examples.
Accumulator factory: 111 examples
[...]</pre>
 
Anonymous user