Anonymous user
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.
Thundergnat (talk | contribs) m (→{{header|Raku}}: typos) |
(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,
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/
subSite = "http://www.rosettacode.org/
var client = newHttpClient()
var sum = 0
let c = client.getContent(subSite % encodeUrl(t)).toLower().count("{{header|")▼
echo t.replace("_", " "), ": ", c, " examples."▼
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.
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>
|