Anonymous user
Rosetta Code/Count examples: Difference between revisions
→{{header|PureBasic}}: Update code to use new Media API and to properly retrieve the plethora of tasks
(→{{header|PureBasic}}: Update code to use new Media API and to properly retrieve the plethora of tasks) |
|||
Line 1,630:
=={{header|PureBasic}}==
<lang PureBasic>
MessageRequester("Error", msg)
End
x1$ = ReadString(0)▼
EndProcedure
handleError(InitNetwork(), "Unable to initialize network functions.")
If OpenConsole()
Define url$, x1$, y1$, title$, unescapedTitle$, encodedURL$
Define x2, i, j, totalExamples, totalTasks
url$ = "http://www.rosettacode.org/mw/api.php?action=query" +
"&list=categorymembers&cmtitle=Category:Programming_Tasks" +
"&cmlimit=500&format=xml"
Repeat
handleError(ReceiveHTTPFile(url$, "tasks.xml"), "Unable to access tasks URL.")
handleError(ReadFile(0, "tasks.xml"), "Unable to read 'task.xml' file.")
▲ x1$ = ReadString(0)
CloseFile(0)
Repeat
x2 = FindString(x1$, "title=", x2 + 1)
If x2
unescapedTitle$ = UnescapeString(ReplaceString(title$, "'", "'"), #PB_String_EscapeXML)
encodedURL$ =
If
ReadFile(0, "task.xml")
While Not
y1$ =
If FindString(y1$, "=={{header|", 1, #PB_String_NoCase)
totalExamples + 1
EndIf
Wend
▲ j = 0
totalTasks + totalExamples
totalExamples = 0
EndIf
EndIf
Until x2 = 0
▲ PrintN("Total: " + Str(k) + " examples")
;check for additional pages of tasks
Input()</lang>▼
x2 = FindString(x1$, "cmcontinue=")
If x2
i = FindString(x1$, #DQUOTE$, x2 + 1)
j = FindString(x1$, #DQUOTE$, i + 1)
url$ = URLEncoder("http://www.rosettacode.org/mw/api.php?action=query" +
"&list=categorymembers&cmtitle=Category:Programming_Tasks" +
"&cmlimit=500&format=xml&cmcontinue=" + Mid(x1$, i + 1, j - i))
Else
Break ;all done
EndIf
ForEver
PrintN("Total: " + Str(totalTasks) + " examples")
CloseConsole()
EndIf</lang>
Sample output:
<pre>100 doors: 224 examples
24 game: 78 examples
24 game/Solve: 46 examples
9 billion names of God the integer: 33 examples
99 Bottles of Beer: 253 examples
A+B: 187 examples
......
Zeckendorf arithmetic: 6 examples
Zeckendorf number representation: 37 examples
Zero to the zero power: 71 examples
Zhang-Suen thinning algorithm: 18 examples
Zig-zag matrix: 83 examples
Total: 44140 examples</pre>
=={{header|Python}}==
|