Rosetta Code/Count examples: Difference between revisions
Content added Content deleted
m (→{{header|OCaml}}: handle 404) |
(→{{header|Oz}}: url-encode task names; update output (currently 14099 examples)) |
||
Line 486: | Line 486: | ||
[StringX] = {Module.link ['x-oz://system/String.ozf']} |
[StringX] = {Module.link ['x-oz://system/String.ozf']} |
||
[Regex] = {Module.link ['x-oz://contrib/regex']} |
[Regex] = {Module.link ['x-oz://contrib/regex']} |
||
AllTasksUrl = "http://rosettacode.org/mw/api.php?action=query&list="# |
AllTasksUrl = "http://rosettacode.org/mw/api.php?action=query&list="# |
||
"categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml" |
"categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml" |
||
proc {Main} |
proc {Main} |
||
AllTasks = {Parse {GetPage AllTasksUrl}} |
AllTasks = {Parse {GetPage AllTasksUrl}} |
||
Line 496: | Line 496: | ||
in |
in |
||
for Task in TaskTitles do |
for Task in TaskTitles do |
||
TaskPage = {GetPage {TaskUrl Task}} |
|||
RE = {Regex.compile "{{header\\|" [extended newline icase]} |
|||
NumMatches = {Length {Regex.allMatches RE TaskPage}} |
|||
in |
in |
||
{System.showInfo Task#": "#NumMatches#" examples."} |
|||
Total := @Total + NumMatches |
|||
end |
end |
||
{System.showInfo "Total: "#@Total#" examples."} |
{System.showInfo "Total: "#@Total#" examples."} |
||
end |
end |
||
fun {TaskUrl Task} |
fun {TaskUrl Task} |
||
"http://rosettacode.org/mw/index.php?"# |
"http://rosettacode.org/mw/index.php?"# |
||
"title="#{StringX.replace Task " " "_"}# |
"title="#{PercentEncode {StringX.replace Task " " "_"}}# |
||
"&action=raw" |
"&action=raw" |
||
end |
end |
||
%% GetPage |
%% GetPage |
||
local |
local |
||
Line 525: | Line 525: | ||
end |
end |
||
end |
end |
||
%% Parse |
%% Parse |
||
local |
local |
||
Line 532: | Line 532: | ||
fun {Parse Xs} {Parser parseVS(Xs $)} end |
fun {Parse Xs} {Parser parseVS(Xs $)} end |
||
end |
end |
||
fun {GetTitles Doc} |
fun {GetTitles Doc} |
||
CMs = Doc.2.1.children.1.children.1.children |
CMs = Doc.2.1.children.1.children.1.children |
||
Line 540: | Line 540: | ||
{Map {Filter {Flatten {Map CMs Attributes}} IsTitle} |
{Map {Filter {Flatten {Map CMs Attributes}} IsTitle} |
||
fun {$ A} {Atom.toString A.value} end} |
fun {$ A} {Atom.toString A.value} end} |
||
end |
|||
fun {PercentEncode Xs} |
|||
case Xs of nil then nil |
|||
[] X|Xr then |
|||
if {Char.isDigit X} orelse {Member X [&- &_ &. &~]} |
|||
orelse X >= &a andthen X =< &z |
|||
orelse X >= &z andthen X =< &Z then |
|||
X|{PercentEncode Xr} |
|||
else |
|||
{Append &%|{ToHex2 X} {PercentEncode Xr}} |
|||
end |
|||
end |
|||
end |
|||
fun {ToHex2 X} |
|||
[{ToHex1 X div 16} {ToHex1 X mod 16}] |
|||
end |
|||
fun {ToHex1 X} |
|||
if X >= 0 andthen X =< 9 then &0 + X |
|||
elseif X >= 10 andthen X =< 15 then &A + X - 10 |
|||
end |
|||
end |
end |
||
in |
in |
||
Line 546: | Line 569: | ||
Example output: |
Example output: |
||
<pre> |
<pre> |
||
100 doors: |
100 doors: 86 examples. |
||
24 game: |
24 game: 22 examples. |
||
24 game/Solve: 15 examples. |
|||
99 Bottles of Beer: 108 examples. |
|||
A+B: 59 examples. |
|||
... |
... |
||
Xiaolin Wu's line algorithm: 5 examples. |
|||
Y combinator: 29 examples. |
|||
Yahoo! Search: 10 examples. |
|||
Zig-zag matrix: 43 examples. |
|||
Total: 14099 examples. |
|||
</pre> |
</pre> |
||