Rosetta Code/Count examples: Difference between revisions
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: Fix broken markup) |
m (→{{header|Wren}}: Minor changes (though see Talk Page re encoding of '+')) |
||
(50 intermediate revisions by 15 users not shown) | |||
Line 10: | Line 10: | ||
Total: X examples.</pre> |
Total: X examples.</pre> |
||
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, [http://rosettacode.org/mw/api.php here], or in Media Wiki's API documentation at, [http://www.mediawiki.org/wiki/API_Query API:Query] |
You'll need to use the Media Wiki API, which you can find out about locally, [http://rosettacode.org/mw/api.php here], or in Media Wiki's API documentation at, [http://www.mediawiki.org/wiki/API_Query API:Query] |
||
Line 16: | Line 18: | ||
{{libheader|AWS}} |
{{libheader|AWS}} |
||
Parsing XML file with XMLAda from AdaCore |
Parsing XML file with XMLAda from AdaCore |
||
< |
<syntaxhighlight lang="ada">with Aws.Client, Aws.Messages, Aws.Response, Aws.Resources, Aws.Url; |
||
with Dom.Readers, Dom.Core, Dom.Core.Documents, Dom.Core.Nodes, Dom.Core.Attrs; |
with Dom.Readers, Dom.Core, Dom.Core.Documents, Dom.Core.Nodes, Dom.Core.Attrs; |
||
with Input_Sources.Strings, Unicode, Unicode.Ces.Utf8; |
with Input_Sources.Strings, Unicode, Unicode.Ces.Utf8; |
||
Line 117: | Line 119: | ||
Put_Line ("Total :" & Integer'Image (Total) & " exemples."); |
Put_Line ("Total :" & Integer'Image (Total) & " exemples."); |
||
end Count_Examples; |
end Count_Examples; |
||
</syntaxhighlight> |
|||
</lang> |
|||
Output : |
Output : |
||
<pre> |
<pre> |
||
Line 128: | Line 130: | ||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
< |
<syntaxhighlight lang="autohotkey">UrlDownloadToFile |
||
, http://www.rosettacode.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml |
, http://www.rosettacode.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml |
||
, tasks.xml |
, tasks.xml |
||
Line 147: | Line 149: | ||
} |
} |
||
MsgBox % output |
MsgBox % output |
||
Return</ |
Return</syntaxhighlight> |
||
=={{header|BBC BASIC}}== |
=={{header|BBC BASIC}}== |
||
{{works with|BBC BASIC for Windows}} |
{{works with|BBC BASIC for Windows}} |
||
< |
<syntaxhighlight lang="bbcbasic"> VDU 23,22,640;512;8,16,16,128+8 : REM Enable UTF-8 support |
||
SYS "LoadLibrary", "URLMON.DLL" TO urlmon% |
SYS "LoadLibrary", "URLMON.DLL" TO urlmon% |
||
Line 234: | Line 236: | ||
WHEN """: = """" |
WHEN """: = """" |
||
ENDCASE |
ENDCASE |
||
= h$</ |
= h$</syntaxhighlight> |
||
'''Sample output:''' |
'''Sample output:''' |
||
<pre> |
<pre> |
||
Line 263: | Line 265: | ||
=={{header|Bracmat}}== |
=={{header|Bracmat}}== |
||
< |
<syntaxhighlight lang="bracmat">( ( get-page |
||
= |
= |
||
. sys$(str$("wget -q -O wget.out \"" !arg \")) |
. sys$(str$("wget -q -O wget.out \"" !arg \")) |
||
Line 303: | Line 305: | ||
) |
) |
||
& lst$(list,taskfreq,NEW) |
& lst$(list,taskfreq,NEW) |
||
)</ |
)</syntaxhighlight> |
||
Output (in file <code>tasqfreq</code>): |
Output (in file <code>tasqfreq</code>): |
||
<pre>list= |
<pre>list= |
||
Line 351: | Line 353: | ||
Object-oriented solution. |
Object-oriented solution. |
||
< |
<syntaxhighlight lang="csharp">using System; |
||
using System.Collections.Generic; |
using System.Collections.Generic; |
||
using System.Linq; |
using System.Linq; |
||
Line 400: | Line 402: | ||
foreach (string task in tasknames) { |
foreach (string task in tasknames) { |
||
try { |
|||
string content = GetSourceCodeFromPage(WebUtility.UrlEncode(task), wc); |
|||
int count = new Regex("=={{header", RegexOptions.IgnoreCase).Matches(content).Count; |
|||
int count = new Regex("=={{header", RegexOptions.IgnoreCase).Matches(content).Count; |
|||
Task t = new Task(task, count); |
|||
Console.WriteLine(t); |
Console.WriteLine(t); |
||
tasks.Add(t); |
tasks.Add(t); |
||
} |
|||
catch (Exception ex) { |
|||
Console.WriteLine("**** Unable to get task \"" + task + "\": " + ex.Message); |
|||
} |
|||
} |
} |
||
Console.WriteLine("\nTotal: {0} examples.", tasks.Select(x => x.Examples).Sum()); |
Console.WriteLine("\nTotal: {0} examples.", tasks.Select(x => x.Examples).Sum()); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Clojure}}== |
=={{header|Clojure}}== |
||
< |
<syntaxhighlight lang="clojure">(ns count-examples |
||
(:import [java.net URLEncoder]) |
(:import [java.net URLEncoder]) |
||
(:use [clojure.contrib.http.agent :only (http-agent string)] |
(:use [clojure.contrib.http.agent :only (http-agent string)] |
||
Line 452: | Line 459: | ||
(flush)) |
(flush)) |
||
(println "Total: " (reduce #(+ %1 (second %2)) 0 task-counts)))) |
(println "Total: " (reduce #(+ %1 (second %2)) 0 task-counts)))) |
||
</syntaxhighlight> |
|||
</lang> |
|||
< |
<syntaxhighlight lang="clojure">count-examples> (print-result) |
||
100 doors: 73 |
100 doors: 73 |
||
24 game: 18 |
24 game: 18 |
||
Line 469: | Line 476: | ||
Total: 11216 |
Total: 11216 |
||
nil |
nil |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|D}}== |
=={{header|D}}== |
||
{{works with|Tango}} |
{{works with|Tango}} |
||
<syntaxhighlight lang="d"> |
|||
<lang D> |
|||
import tango.io.Stdout; |
import tango.io.Stdout; |
||
import tango.net.http.HttpClient; |
import tango.net.http.HttpClient; |
||
Line 522: | Line 529: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|EGL}}== |
=={{header|EGL}}== |
||
Line 530: | Line 537: | ||
User Interface: RosettaCodeHandler.egl |
User Interface: RosettaCodeHandler.egl |
||
< |
<syntaxhighlight lang="egl">package com.eglexamples.client; |
||
import org.eclipse.edt.rui.widgets.*; |
import org.eclipse.edt.rui.widgets.*; |
||
Line 605: | Line 612: | ||
title string; |
title string; |
||
count int; |
count int; |
||
end</ |
end</syntaxhighlight> |
||
Service Interface: ProxyFunctions.egl |
Service Interface: ProxyFunctions.egl |
||
< |
<syntaxhighlight lang="egl">package com.eglexamples.client; |
||
library ProxyFunctions |
library ProxyFunctions |
||
Line 644: | Line 651: | ||
record QueryContinue |
record QueryContinue |
||
categorymembers Categorymembers; |
categorymembers Categorymembers; |
||
end</ |
end</syntaxhighlight> |
||
=={{header|Erlang}}== |
=={{header|Erlang}}== |
||
Line 651: | Line 657: | ||
{{libheader|xmerl}} |
{{libheader|xmerl}} |
||
< |
<syntaxhighlight lang="erlang"> |
||
-module(rosseta_examples). |
-module(rosseta_examples). |
||
-include_lib("xmerl/include/xmerl.hrl"). |
-include_lib("xmerl/include/xmerl.hrl"). |
||
Line 714: | Line 720: | ||
replace_chars([],Acc) -> |
replace_chars([],Acc) -> |
||
lists:reverse(Acc). |
lists:reverse(Acc). |
||
</syntaxhighlight> |
|||
</lang> |
|||
Line 734: | Line 740: | ||
Using asynchronous workflows to perform downloads concurrently: |
Using asynchronous workflows to perform downloads concurrently: |
||
< |
<syntaxhighlight lang="fsharp">#r "System.Xml.Linq.dll" |
||
let uri1 = "http://www.rosettacode.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml" |
let uri1 = "http://www.rosettacode.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml" |
||
Line 751: | Line 757: | ||
|> Async.Parallel |
|> Async.Parallel |
||
|> Async.RunSynchronously |
|> Async.RunSynchronously |
||
|> fun xs -> printfn "Total: %d examples" (Seq.sum xs)</ |
|> fun xs -> printfn "Total: %d examples" (Seq.sum xs)</syntaxhighlight> |
||
This is 21× faster than the python thanks to the concurrency. |
This is 21× faster than the python thanks to the concurrency. |
||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
Runs in about a minute. The number of threads is limited to 10 avoid cloudfare's protection mechanism. |
Runs in about a minute. The number of threads is limited to 10 avoid cloudfare's protection mechanism. |
||
< |
<syntaxhighlight lang="factor">USING: arrays assocs concurrency.combinators |
||
concurrency.semaphores formatting hashtables http.client io |
concurrency.semaphores formatting hashtables http.client io |
||
json.reader kernel math math.parser sequences splitting |
json.reader kernel math math.parser sequences splitting |
||
Line 798: | Line 805: | ||
all-programming-titles fetch-counts print-counts ; |
all-programming-titles fetch-counts print-counts ; |
||
MAIN: rosetta-examples</ |
MAIN: rosetta-examples</syntaxhighlight> |
||
Outputs: |
Outputs: |
||
Line 808: | Line 815: | ||
Total: 30745 examples.</pre> |
Total: 30745 examples.</pre> |
||
=={{header|Go}}== |
=={{header|Go}}== |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 883: | Line 891: | ||
fmt.Printf("%s: %d\n", cm, examples) |
fmt.Printf("%s: %d\n", cm, examples) |
||
total += examples |
total += examples |
||
}</ |
}</syntaxhighlight> |
||
{{out|Output: (May 25, 2011)}} |
{{out|Output: (May 25, 2011)}} |
||
<pre> |
<pre> |
||
Line 897: | Line 905: | ||
{{libheader|HTTP XML}} from [http://hackage.haskell.org/packages/hackage.html HackageDB] |
{{libheader|HTTP XML}} from [http://hackage.haskell.org/packages/hackage.html HackageDB] |
||
< |
<syntaxhighlight lang="haskell">import Network.Browser |
||
import Network.HTTP |
import Network.HTTP |
||
import Network.URI |
import Network.URI |
||
Line 933: | Line 941: | ||
mapM_ putStrLn $ zipWith showFormatted tasks ns |
mapM_ putStrLn $ zipWith showFormatted tasks ns |
||
putStrLn $ ("Total: " ++) $ show tot</ |
putStrLn $ ("Total: " ++) $ show tot</syntaxhighlight> |
||
some output: |
some output: |
||
< |
<syntaxhighlight lang="haskell">*Main> progTaskExamples |
||
100 doors: 56 |
100 doors: 56 |
||
24 game: 11 |
24 game: 11 |
||
Line 944: | Line 952: | ||
Active object: 9 |
Active object: 9 |
||
... |
... |
||
Total: 9156</ |
Total: 9156</syntaxhighlight> |
||
==Icon and {{header|Unicon}}== |
==Icon and {{header|Unicon}}== |
||
The following code uses features exclusive to Unicon. This version handles all tasks, not just the first 500. |
The following code uses features exclusive to Unicon. This version handles all tasks, not just the first 500. |
||
< |
<syntaxhighlight lang="unicon">$define RCINDEX "http://rosettacode.org/mw/api.php?format=xml&action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500" |
||
$define RCTASK "http://rosettacode.org/mw/index.php?action=raw&title=" |
$define RCTASK "http://rosettacode.org/mw/index.php?action=raw&title=" |
||
$define RCUA "User-Agent: Unicon Rosetta 0.1" |
$define RCUA "User-Agent: Unicon Rosetta 0.1" |
||
Line 1,030: | Line 1,038: | ||
close(page) |
close(page) |
||
return text |
return text |
||
end</ |
end</syntaxhighlight> |
||
{{libheader|Icon Programming Library}} |
{{libheader|Icon Programming Library}} |
||
Line 1,062: | Line 1,070: | ||
'''Solution:'''<br> |
'''Solution:'''<br> |
||
Using <code>getCategoryMembers</code> from [[Find unimplemented tasks#J|Find unimplemented tasks]]. |
Using <code>getCategoryMembers</code> from [[Find unimplemented tasks#J|Find unimplemented tasks]]. |
||
< |
<syntaxhighlight lang="j">require 'web/gethttp' |
||
getAllTaskSolnCounts=: monad define |
getAllTaskSolnCounts=: monad define |
||
Line 1,081: | Line 1,089: | ||
res=. ;:^:_1 tasks ,. (8!:0 counts) ,. <'examples.' |
res=. ;:^:_1 tasks ,. (8!:0 counts) ,. <'examples.' |
||
res , 'Total examples: ' , ": +/counts |
res , 'Total examples: ' , ": +/counts |
||
)</ |
)</syntaxhighlight> |
||
'''Example Usage:''' |
'''Example Usage:''' |
||
< |
<syntaxhighlight lang="j"> formatSolnCounts getAllTaskSolnCounts '' |
||
100 doors: 61 examples. |
100 doors: 61 examples. |
||
24 game: 15 examples. |
24 game: 15 examples. |
||
24 game Player: 11 examples. |
24 game Player: 11 examples. |
||
99 Bottles of Beer: 76 examples. |
99 Bottles of Beer: 76 examples. |
||
...</ |
...</syntaxhighlight> |
||
=={{header|Java}}== |
=={{header|Java}}== |
||
{{works with|Java|1.5+}} |
{{works with|Java|1.5+}} |
||
< |
<syntaxhighlight lang="java5"> |
||
import java.util.ArrayList; |
import java.util.ArrayList; |
||
import ScreenScrape; |
import ScreenScrape; |
||
Line 1,163: | Line 1,171: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
[[Count programming examples/Java/ScreenScrape|ScreenScrape class]] |
[[Count programming examples/Java/ScreenScrape|ScreenScrape class]] |
||
=={{header|jq}}== |
=={{header|jq}}== |
||
Line 1,173: | Line 1,179: | ||
`@uri` filter in the bash function `titles`. |
`@uri` filter in the bash function `titles`. |
||
< |
<syntaxhighlight lang="bash">#!/bin/bash |
||
# Produce lines of the form: URI TITLE |
# Produce lines of the form: URI TITLE |
||
Line 1,197: | Line 1,203: | ||
n=$((n + i)) |
n=$((n + i)) |
||
done < <(titles) |
done < <(titles) |
||
echo Total: $n examples.</ |
echo Total: $n examples.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,210: | Line 1,216: | ||
Palindrome detection: 136 examples. |
Palindrome detection: 136 examples. |
||
Total: 32416 examples.</pre> |
Total: 32416 examples.</pre> |
||
=={{header|Julia}}== |
|||
Output by page is too long, so summaries only output shown. |
|||
<syntaxhighlight lang="julia">using HTTP, JSON, Dates |
|||
rosorg = "http://rosettacode.org" |
|||
qURI = "/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=json" |
|||
qdURI = "/w/api.php?action=query&list=categorymembers&cmtitle=Category:Draft_Programming_Tasks&cmlimit=500&format=json" |
|||
sqURI = rosorg * "/wiki/" |
|||
topages(js, v) = for d in js["query"]["categorymembers"] push!(v, sqURI * replace(d["title"], " " => "_")) end |
|||
function getpages(uri) |
|||
wikipages = Vector{String}() |
|||
response = HTTP.request("GET", rosorg * uri) |
|||
if response.status == 200 |
|||
fromjson = JSON.parse(String(response.body)) |
|||
topages(fromjson, wikipages) |
|||
while haskey(fromjson, "continue") |
|||
cmcont, cont = fromjson["continue"]["cmcontinue"], fromjson["continue"]["continue"] |
|||
response = HTTP.request("GET", rosorg * uri * "&cmcontinue=$cmcont&continue=$cont") |
|||
fromjson = JSON.parse(String(response.body)) |
|||
topages(fromjson, wikipages) |
|||
end |
|||
end |
|||
wikipages |
|||
end |
|||
function processtaskpages(wpages, verbose=false) |
|||
totalexamples = 0 |
|||
for pag in wpages |
|||
response = HTTP.request("GET", pag) |
|||
if response.status == 200 |
|||
n = length(collect(eachmatch(r"span class=\"mw-headline\"", String(response.body)))) |
|||
if verbose |
|||
println("Wiki page $pag => $n examples.") |
|||
end |
|||
totalexamples += n |
|||
end |
|||
end |
|||
println("Total of $totalexamples on $(length(wpages)) task pages.\n") |
|||
end |
|||
println("Programming examples at $(DateTime(now())):") |
|||
qURI |> getpages |> processtaskpages |
|||
println("Draft programming tasks:") |
|||
qdURI |> getpages |> processtaskpages |
|||
</syntaxhighlight>{{out}} |
|||
<pre> |
|||
Programming examples at 2019-02-16T21:04:15.583: |
|||
Total of 66388 on 928 task pages. |
|||
Draft programming tasks: |
|||
Total of 3385 on 216 task pages. |
|||
</pre> |
|||
=={{header|Lasso}}== |
=={{header|Lasso}}== |
||
< |
<syntaxhighlight lang="lasso">local(root = json_deserialize(curl('http://rosettacode.org/mw/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=10&format=json')->result)) |
||
local(tasks = array, title = string, urltitle = string, thiscount = 0, totalex = 0) |
local(tasks = array, title = string, urltitle = string, thiscount = 0, totalex = 0) |
||
with i in #root->find('query')->find('categorymembers') do => {^ |
with i in #root->find('query')->find('categorymembers') do => {^ |
||
Line 1,228: | Line 1,290: | ||
'\r' |
'\r' |
||
^} |
^} |
||
'Total: '+#totalex+' examples.'</ |
'Total: '+#totalex+' examples.'</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,250: | Line 1,312: | ||
2. Add a text field called "tasks" |
2. Add a text field called "tasks" |
||
n.b. The list of tasks is limited to 10 for demo purposes< |
n.b. The list of tasks is limited to 10 for demo purposes<syntaxhighlight lang="livecode">on mouseUp |
||
put empty into fld "taskurls" |
put empty into fld "taskurls" |
||
put URL "http://rosettacode.org/mw/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=10&format=xml" into apixml |
put URL "http://rosettacode.org/mw/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=10&format=xml" into apixml |
||
Line 1,266: | Line 1,328: | ||
end repeat |
end repeat |
||
put "Total" & comma & allTaskTotal after fld "tasks" |
put "Total" & comma & allTaskTotal after fld "tasks" |
||
end mouseUp</ |
end mouseUp</syntaxhighlight> |
||
=={{header| |
=={{header|Maple}}== |
||
<syntaxhighlight lang="maple">ConvertUTF8 := proc( str ) |
|||
<lang Mathematica>TaskList = Flatten[ |
|||
local i, tempstring, uniindex; |
|||
Import["http://rosettacode.org/wiki/Category:Programming_Tasks", "Data"][[1, 1]]]; |
|||
try |
|||
tempstring := str; |
|||
uniindex := [StringTools:-SearchAll("\u",str)]; |
|||
if uniindex <> [] then |
|||
for i in uniindex do |
|||
tempstring := StringTools:-Substitute(tempstring, str[i..i+5], UTF8:-unicode(str[i+2..i+5])); |
|||
end do: |
|||
end if; |
|||
return tempstring; |
|||
catch: |
|||
return str; |
|||
end try; |
|||
end proc: |
|||
print_examples := proc(lst) |
|||
local task, count, url, headers, item; |
|||
for task in lst do |
|||
count := 0: |
|||
url := cat("http://www.rosettacode.org/mw/index.php?title=", StringTools:-Encode(StringTools:-SubstituteAll(task["title"], " ", "_"), 'percent'), "&action=raw"): |
|||
headers := [StringTools:-SearchAll("=={{header|",URL:-Get(url))]: |
|||
for item in headers do |
|||
count++: |
|||
end do: |
|||
printf("%s has %d examples\n",ConvertUTF8(task["title"]), count); |
|||
end do: |
|||
end proc: |
|||
x := JSON:-ParseFile("http://rosettacode.org/mw/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=20&format=json"): |
|||
print_examples(x["query"]["categorymembers"]); |
|||
while(assigned(x["continue"]["cmcontinue"])) do |
|||
continue := x["continue"]["cmcontinue"]: |
|||
more_tasks:= cat("http://rosettacode.org/mw/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=20&format=json", "&continue=", x["continue"]["continue"], "&cmcontinue=", x["continue"]["cmcontinue"]): |
|||
x := JSON:-ParseFile(more_tasks): |
|||
print_examples(x["query"]["categorymembers"]); |
|||
end do: |
|||
</syntaxhighlight> |
|||
{{Out|Output}} |
|||
<pre> |
|||
100 doors has 267 examples |
|||
15 Puzzle Game has 42 examples |
|||
15 puzzle solver has 4 examples |
|||
2048 has 34 examples |
|||
24 game has 88 examples |
|||
24 game/Solve has 54 examples |
|||
4-rings or 4-squares puzzle has 33 examples |
|||
9 billion names of God the integer has 42 examples |
|||
99 Bottles of Beer has 291 examples |
|||
A+B has 224 examples |
|||
ABC Problem has 104 examples |
|||
Abstract type has 77 examples |
|||
Abundant, deficient and perfect number classifications has 69 examples |
|||
Accumulator factory has 97 examples |
|||
Ackermann function has 194 examples |
|||
Active Directory/Connect has 24 examples |
|||
Active Directory/Search for a user has 16 examples |
|||
Active object has 37 examples |
|||
Add a variable to a class instance at runtime has 51 examples |
|||
Address of a variable has 69 examples |
|||
AKS test for primes has 55 examples |
|||
Align columns has 97 examples |
|||
Aliquot sequence classifications has 32 examples |
|||
Almost prime has 58 examples |
|||
Amb has 35 examples |
|||
Amicable pairs has 69 examples |
|||
Anagrams has 99 examples |
|||
Anagrams/Deranged anagrams has 63 examples |
|||
Angle difference between two bearings has 24 examples |
|||
Animate a pendulum has 55 examples |
|||
Animation has 61 examples |
|||
Anonymous recursion has 86 examples |
|||
Append a record to the end of a text file has 36 examples |
|||
Apply a callback to an array has 144 examples |
|||
Apply a digital filter (direct form II transposed) has 14 examples |
|||
Arbitrary-precision integers (included) has 84 examples |
|||
Archimedean spiral has 40 examples |
|||
Arena storage pool has 25 examples |
|||
Arithmetic evaluation has 51 examples |
|||
Arithmetic-geometric mean has 93 examples |
|||
Arithmetic-geometric mean/Calculate Pi has 23 examples |
|||
Arithmetic/Complex has 101 examples |
|||
Arithmetic/Integer has 176 examples |
|||
Arithmetic/Rational has 59 examples |
|||
Array concatenation has 159 examples |
|||
Array length has 124 examples |
|||
Arrays has 188 examples |
|||
Assertions has 96 examples |
|||
Associative array/Creation has 128 examples |
|||
Associative array/Iteration has 107 examples |
|||
Atomic updates has 38 examples |
|||
Average loop length has 34 examples |
|||
Averages/Arithmetic mean has 168 examples |
|||
Averages/Mean angle has 63 examples |
|||
Averages/Mean time of day has 50 examples |
|||
Averages/Median has 103 examples |
|||
Averages/Mode has 76 examples |
|||
Averages/Pythagorean means has 96 examples |
|||
Averages/Root mean square has 111 examples |
|||
Averages/Simple moving average has 78 examples |
|||
AVL tree has 18 examples |
|||
Babbage problem has 80 examples |
|||
Balanced brackets has 112 examples |
|||
Balanced ternary has 34 examples |
|||
Barnsley fern has 39 examples |
|||
Benford's law has 58 examples |
|||
Bernoulli numbers has 43 examples |
|||
... |
|||
Variable size/Set has 37 examples |
|||
Variable-length quantity has 35 examples |
|||
Variables has 109 examples |
|||
Variadic function has 94 examples |
|||
Vector products has 77 examples |
|||
Verify distribution uniformity/Chi-squared test has 21 examples |
|||
Verify distribution uniformity/Naive has 40 examples |
|||
Video display modes has 13 examples |
|||
Vigenère cipher has 0 examples |
|||
Vigenère cipher/Cryptanalysis has 0 examples |
|||
Visualize a tree has 35 examples |
|||
Vogel's approximation method has 12 examples |
|||
Voronoi diagram has 32 examples |
|||
Walk a directory/Non-recursively has 84 examples |
|||
Walk a directory/Recursively has 75 examples |
|||
Water collected between towers has 28 examples |
|||
Web scraping has 75 examples |
|||
Window creation has 81 examples |
|||
Window creation/X11 has 23 examples |
|||
Window management has 19 examples |
|||
Wireworld has 47 examples |
|||
Word search has 9 examples |
|||
Word wrap has 63 examples |
|||
World Cup group stage has 14 examples |
|||
Write entire file has 53 examples |
|||
Write float arrays to a text file has 64 examples |
|||
Write language name in 3D ASCII has 59 examples |
|||
Write to Windows event log has 23 examples |
|||
Xiaolin Wu's line algorithm has 25 examples |
|||
XML/DOM serialization has 45 examples |
|||
XML/Input has 68 examples |
|||
XML/Output has 55 examples |
|||
XML/XPath has 52 examples |
|||
Y combinator has 81 examples |
|||
Yahoo! search interface has 19 examples |
|||
Yin and yang has 53 examples |
|||
Zebra puzzle has 39 examples |
|||
Zeckendorf arithmetic has 10 examples |
|||
Zeckendorf number representation has 57 examples |
|||
Zero to the zero power has 94 examples |
|||
Zhang-Suen thinning algorithm has 26 examples |
|||
Zig-zag matrix has 92 examples |
|||
</pre> |
|||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
|||
<syntaxhighlight lang="mathematica">TaskList = Flatten[ |
|||
Import["http://rosettacode.org/wiki/Category:Programming_Tasks", "Data"][[1, 1]]]; |
|||
Print["Task \"", StringReplace[#, "_" -> " "], "\" has ", |
Print["Task \"", StringReplace[#, "_" -> " "], "\" has ", |
||
Length@Select[Import["http://rosettacode.org/wiki/" <> #, "Data"][[1,2]], |
Length@Select[Import["http://rosettacode.org/wiki/" <> #, "Data"][[1,2]], |
||
StringFreeQ[#, __ ~~ "Programming Task" | __ ~~ "Omit"]& ], " example(s)"]& |
StringFreeQ[#, __ ~~ "Programming Task" | __ ~~ "Omit"]& ], " example(s)"]& |
||
~Map~ StringReplace[TaskList, " " -> "_"]</ |
~Map~ StringReplace[TaskList, " " -> "_"]</syntaxhighlight> |
||
returns: |
returns: |
||
<pre>Task "100 doors" has 143 example(s) |
<pre>Task "100 doors" has 143 example(s) |
||
Line 1,285: | Line 1,499: | ||
The function count_examples() need to be saved in a file count_examples.m and its directory need to be included in the path. |
The function count_examples() need to be saved in a file count_examples.m and its directory need to be included in the path. |
||
< |
<syntaxhighlight lang="matlab"> function c = count_examples(url) |
||
c = 0; |
c = 0; |
||
[s, success] = urlread (url); |
[s, success] = urlread (url); |
||
Line 1,302: | Line 1,516: | ||
c = count_examples(['http://rosettacode.org',t]); |
c = count_examples(['http://rosettacode.org',t]); |
||
printf('Task "%s" has %i examples.\n',t(7:end), c); |
printf('Task "%s" has %i examples.\n',t(7:end), c); |
||
end; </ |
end; </syntaxhighlight> |
||
Output: |
Output: |
||
Line 1,314: | Line 1,528: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
< |
<syntaxhighlight lang="nim">import httpclient, strutils, xmltree, xmlparser, cgi |
||
proc count(s, sub): int = |
proc count(s, sub: string): int = |
||
var i = 0 |
var i = 0 |
||
while true: |
while true: |
||
i = s.find(sub, i) |
i = s.find(sub, i) |
||
if i < 0: |
if i < 0: break |
||
break |
|||
inc i |
inc i |
||
inc result |
inc result |
||
const |
const |
||
mainSite = "http://www.rosettacode.org/ |
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/ |
subSite = "http://www.rosettacode.org/mw/index.php?title=$#&action=raw" |
||
var client = newHttpClient() |
|||
var sum = 0 |
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."</syntaxhighlight> |
|||
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: |
|||
100 prisoners: 55 examples. |
|||
15 puzzle game: 71 examples. |
|||
15 puzzle solver: 18 examples. |
|||
2048: 57 examples. |
|||
21 game: 37 examples. |
|||
24 game: 100 examples. |
|||
24 game/Solve: 64 examples. |
|||
4-rings or 4-squares puzzle: 57 examples. |
|||
9 billion names of God the integer: 60 examples. |
|||
99 bottles of beer: 347 examples. |
|||
A+B: 278 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> |
[...]</pre> |
||
=={{header|Objeck}}== |
=={{header|Objeck}}== |
||
< |
<syntaxhighlight lang="objeck">use HTTP; |
||
use XML; |
use XML; |
||
Line 1,390: | Line 1,615: | ||
return xml; |
return xml; |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
Output:<pre>Amb: 28 |
Output:<pre>Amb: 28 |
||
Line 1,423: | Line 1,648: | ||
ocamlfind opt -linkpkg -package str,unix,xml-light,netclient countex.ml -o countex.opt |
ocamlfind opt -linkpkg -package str,unix,xml-light,netclient countex.ml -o countex.opt |
||
< |
<syntaxhighlight lang="ocaml">open Http_client.Convenience |
||
Line 1,484: | Line 1,709: | ||
let catmb = get_child "categorymembers" query in |
let catmb = get_child "categorymembers" query in |
||
List.iter f catmb |
List.iter f catmb |
||
| _ -> ()</ |
| _ -> ()</syntaxhighlight> |
||
outputs: |
outputs: |
||
Line 1,511: | Line 1,736: | ||
{{libheader|OzHttpClient}} |
{{libheader|OzHttpClient}} |
||
< |
<syntaxhighlight lang="oz">declare |
||
[HTTPClient] = {Module.link ['x-ozlib://mesaros/net/HTTPClient.ozf']} |
[HTTPClient] = {Module.link ['x-ozlib://mesaros/net/HTTPClient.ozf']} |
||
[XMLParser] = {Module.link ['x-oz://system/xml/Parser.ozf']} |
[XMLParser] = {Module.link ['x-oz://system/xml/Parser.ozf']} |
||
Line 1,595: | Line 1,820: | ||
end |
end |
||
in |
in |
||
{Main}</ |
{Main}</syntaxhighlight> |
||
Example output: |
Example output: |
||
Line 1,613: | Line 1,838: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
< |
<syntaxhighlight lang="perl">use HTTP::Tiny; |
||
my $site = "http://rosettacode.org"; |
my $site = "http://rosettacode.org"; |
||
my $list_url = "/ |
my $list_url = "/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml"; |
||
my $response = HTTP::Tiny->new->get("$site$list_url"); |
|||
for ($response->{content} =~ /cm.*?title="(.*?)"/g) { |
|||
(my $slug = $_) =~ tr/ /_/; |
(my $slug = $_) =~ tr/ /_/; |
||
my $ |
my $response = HTTP::Tiny->new->get("$site/wiki/$slug"); |
||
my $count = () = $response->{content} =~ /toclevel-1/g; |
|||
print "$_: $count examples\n"; |
print "$_: $count examples\n"; |
||
}</ |
}</syntaxhighlight> |
||
{{libheader|Mojolicious}} |
{{libheader|Mojolicious}} |
||
<syntaxhighlight lang="perl">use Mojo::UserAgent; |
|||
<lang Perl>use v5.10; |
|||
use Mojo::UserAgent; |
|||
my $site = "http://rosettacode.org"; |
my $site = "http://rosettacode.org"; |
||
Line 1,636: | Line 1,862: | ||
my $count = $ua->get("$site/wiki/$slug")->res->dom->find("#toc .toclevel-1")->size; |
my $count = $ua->get("$site/wiki/$slug")->res->dom->find("#toc .toclevel-1")->size; |
||
say "$_->{title}: $count examples"; |
say "$_->{title}: $count examples"; |
||
});</ |
});</syntaxhighlight> |
||
=={{header|Perl 6}}== |
|||
{{works with|Rakudo|2018.03}} |
|||
<lang perl6>use HTTP::UserAgent; |
|||
use URI::Escape; |
|||
use JSON::Fast; |
|||
=={{header|Phix}}== |
|||
# Friendlier descriptions for task categories |
|||
First, some common code used by several tasks: |
|||
my %cat = ( |
|||
<!--<syntaxhighlight lang="phix">(notonline)--> |
|||
'Programming_Tasks' => 'Task', |
|||
<span style="color: #000080;font-style:italic;">-- |
|||
'Draft_Programming_Tasks' => 'Draft' |
|||
-- demo\rosetta\rosettacode_cache.e |
|||
); |
|||
-- ================================ |
|||
-- |
|||
my $client = HTTP::UserAgent.new; |
|||
-- Common routines for handling rc_cache etc. |
|||
--</span> |
|||
my $url = 'http://rosettacode.org/mw'; |
|||
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (libcurl, file i/o, peek, progress..)</span> |
|||
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins</span><span style="color: #0000FF;">\</span><span style="color: #004080;">timedate</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> |
|||
my $hashfile = './RC_Task_count.json'; |
|||
<span style="color: #008080;">constant</span> <span style="color: #000000;">day</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">timedelta</span><span style="color: #0000FF;">(</span><span style="color: #000000;">days</span><span style="color: #0000FF;">:=</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span> |
|||
my $tablefile = './RC_Task_count.txt'; |
|||
<span style="color: #004080;">integer</span> <span style="color: #000000;">refresh_cache</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">21</span><span style="color: #0000FF;">*</span><span style="color: #000000;">day</span> <span style="color: #000080;font-style:italic;">-- 0 for always [NB refresh_cache += timedelta(days:=1) below]</span> |
|||
my %tasks; |
|||
<span style="color: #008080;">function</span> <span style="color: #000000;">days</span><span style="color: #0000FF;">(</span><span style="color: #004080;">atom</span> <span style="color: #000000;">delta</span><span style="color: #0000FF;">)</span> |
|||
<span style="color: #004080;">integer</span> <span style="color: #000000;">d</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">ceil</span><span style="color: #0000FF;">(</span><span style="color: #000000;">delta</span><span style="color: #0000FF;">/</span><span style="color: #000000;">day</span><span style="color: #0000FF;">)</span> |
|||
#=begin update |
|||
<span style="color: #008080;">return</span> <span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%d day%s"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">d</span><span style="color: #0000FF;">,</span><span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">d</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span><span style="color: #0000FF;">?</span><span style="color: #008000;">""</span><span style="color: #0000FF;">:</span><span style="color: #008000;">"s"</span><span style="color: #0000FF;">)})</span> |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span> |
|||
note 'Retrieving task information...'; |
|||
<span style="color: #008080;">constant</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">hex</span><span style="color: #0000FF;">,</span><span style="color: #000000;">ascii</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">columnize</span><span style="color: #0000FF;">({{</span><span style="color: #008000;">"%22"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`"`</span><span style="color: #0000FF;">},</span> |
|||
for %cat.keys -> $cat { |
|||
<span style="color: #0000FF;">{</span><span style="color: #008000;">"%27"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"'"</span><span style="color: #0000FF;">},</span> |
|||
mediawiki-query( |
|||
<span style="color: #0000FF;">{</span><span style="color: #008000;">"%2A"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"*"</span><span style="color: #0000FF;">},</span> |
|||
$url, 'pages', |
|||
<span style="color: #0000FF;">{</span><span style="color: #008000;">"%2B"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"+"</span><span style="color: #0000FF;">},</span> |
|||
:generator<categorymembers>, |
|||
<span style="color: #0000FF;">{</span><span style="color: #008000;">"%3A"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">":"</span><span style="color: #0000FF;">},</span> |
|||
:gcmtitle("Category:$cat"), |
|||
<span style="color: #0000FF;">{</span><span style="color: #008000;">"%5E"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`^`</span><span style="color: #0000FF;">},</span> |
|||
:gcmlimit<350>, |
|||
<span style="color: #0000FF;">{</span><span style="color: #008000;">"%E2%80%93"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"-"</span><span style="color: #0000FF;">},</span> |
|||
:rawcontinue(), |
|||
<span style="color: #0000FF;">{</span><span style="color: #008000;">"%E2%80%99"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"'"</span><span style="color: #0000FF;">},</span> |
|||
:prop<title> |
|||
<span style="color: #0000FF;">{</span><span style="color: #008000;">"%C3%A8"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"e"</span><span style="color: #0000FF;">},</span> |
|||
).map({ |
|||
<span style="color: #0000FF;">{</span><span style="color: #008000;">"%C3%A9"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"e"</span><span style="color: #0000FF;">},</span> |
|||
my $page = mediawiki-query( |
|||
<span style="color: #0000FF;">{</span><span style="color: #008000;">"%C3%B6"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"o"</span><span style="color: #0000FF;">},</span> |
|||
$url, 'pages', |
|||
<span style="color: #0000FF;">{</span><span style="color: #008000;">"%C5%91"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"o"</span><span style="color: #0000FF;">},</span> |
|||
:titles(.<title>), |
|||
<span style="color: #0000FF;">{</span><span style="color: #008000;">"""</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`"`</span><span style="color: #0000FF;">},</span> |
|||
:prop<revisions>, |
|||
<span style="color: #0000FF;">{</span><span style="color: #008000;">"'"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"'"</span><span style="color: #0000FF;">},</span> |
|||
:rvprop<content>, |
|||
<span style="color: #0000FF;">{</span><span style="color: #008000;">"_"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" "</span><span style="color: #0000FF;">}})</span> |
|||
); |
|||
my $count = +$page.comb(/'=={{header|'/); |
|||
<span style="color: #008080;">global</span> <span style="color: #008080;">function</span> <span style="color: #000000;">html_clean</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span> |
|||
%tasks{.<title>} = {'cat' => %cat{$cat}, :$count}; |
|||
<span style="color: #008080;">return</span> <span style="color: #7060A8;">substitute_all</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">,</span><span style="color: #000000;">hex</span><span style="color: #0000FF;">,</span><span style="color: #000000;">ascii</span><span style="color: #0000FF;">)</span> |
|||
(state $throbber += 1) mod= 40; |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span> |
|||
print "\b" x 40, ' ' x 40, "\b" x 40, '█' x $throbber; |
|||
}) |
|||
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins</span><span style="color: #0000FF;">\</span><span style="color: #000000;">libcurl</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> |
|||
} |
|||
<span style="color: #004080;">atom</span> <span style="color: #000000;">curl</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">NULL</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">pErrorBuffer</span> |
|||
print "\b" x 40, ' ' x 40, "\b" x 40; |
|||
<span style="color: #008080;">function</span> <span style="color: #000000;">write_callback</span><span style="color: #0000FF;">(</span><span style="color: #004080;">atom</span> <span style="color: #000000;">pData</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">size</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">nmemb</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">fn</span><span style="color: #0000FF;">)</span> |
|||
<span style="color: #004080;">integer</span> <span style="color: #000000;">bytes_written</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">size</span> <span style="color: #0000FF;">*</span> <span style="color: #000000;">nmemb</span> |
|||
note "\nTask information saved to local file: {$hashfile.IO.absolute}"; |
|||
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">fn</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">peek</span><span style="color: #0000FF;">({</span><span style="color: #000000;">pData</span><span style="color: #0000FF;">,</span><span style="color: #000000;">bytes_written</span><span style="color: #0000FF;">}))</span> |
|||
$hashfile.IO.spurt(%tasks.&to-json); |
|||
<span style="color: #008080;">return</span> <span style="color: #000000;">bytes_written</span> |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span> |
|||
#=end update |
|||
<span style="color: #008080;">constant</span> <span style="color: #000000;">write_cb</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">call_back</span><span style="color: #0000FF;">({</span><span style="color: #008000;">'+'</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">write_callback</span><span style="color: #0000FF;">})</span> |
|||
# Load information from local file |
|||
<span style="color: #008080;">global</span> <span style="color: #004080;">string</span> <span style="color: #000000;">wastitle</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">""</span> <span style="color: #000080;font-style:italic;">-- don't clobber "NEED EDITING"/Downloading messages</span> |
|||
%tasks = $hashfile.IO.e ?? $hashfile.IO.slurp.&from-json !! ( ); |
|||
<span style="color: #008080;">global</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">show_title</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">progress</span> |
|||
# Convert saved task / author info to a table |
|||
<span style="color: #008080;">global</span> <span style="color: #008080;">function</span> <span style="color: #000000;">open_download</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">filename</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">url</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span><span style="color: #0000FF;">)</span> |
|||
note "\nBuilding table..."; |
|||
<span style="color: #004080;">object</span> <span style="color: #000000;">text</span> |
|||
my $count = +%tasks; |
|||
<span style="color: #004080;">bool</span> <span style="color: #000000;">refetch</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">false</span> |
|||
my $taskcnt = +%tasks.grep: *.value.<cat> eq %cat<Programming_Tasks>; |
|||
<span style="color: #004080;">string</span> <span style="color: #000000;">why</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"not found"</span> |
|||
my $draftcnt = $count - $taskcnt; |
|||
<span style="color: #000000;">filename</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">join_path</span><span style="color: #0000FF;">({</span><span style="color: #008000;">"rc_cache"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">filename</span><span style="color: #0000FF;">})</span> |
|||
<span style="color: #008080;">if</span> <span style="color: #7060A8;">file_exists</span><span style="color: #0000FF;">(</span><span style="color: #000000;">filename</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span> |
|||
# Dump table to a file |
|||
<span style="color: #000080;font-style:italic;">-- use existing file if <= refresh_cache days old</span> |
|||
my $out = open($tablefile, :w) or die "$!\n"; |
|||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">last_mod</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">get_file_date</span><span style="color: #0000FF;">(</span><span style="color: #000000;">filename</span><span style="color: #0000FF;">)</span> |
|||
<span style="color: #004080;">atom</span> <span style="color: #000000;">delta</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">timedate_diff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">last_mod</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">date</span><span style="color: #0000FF;">())</span> |
|||
# Add table boilerplate and caption |
|||
<span style="color: #000000;">refetch</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">true</span> |
|||
$out.say: |
|||
<span style="color: #008080;">if</span> <span style="color: #000000;">delta</span><span style="color: #0000FF;">></span><span style="color: #000000;">refresh_cache</span> |
|||
'<div style="height:80ex;overflow:scroll;">', "\n", |
|||
<span style="color: #008080;">and</span> <span style="color: #008080;">not</span> <span style="color: #7060A8;">match</span><span style="color: #0000FF;">(</span><span style="color: #008000;">".hist"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">filename</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span> |
|||
'{|class="wikitable sortable"', "\n", |
|||
<span style="color: #000000;">why</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">days</span><span style="color: #0000FF;">(</span><span style="color: #000000;">delta</span><span style="color: #0000FF;">)</span> <span style="color: #0000FF;">&</span> <span style="color: #008000;">" > "</span> <span style="color: #0000FF;">&</span> <span style="color: #000000;">days</span><span style="color: #0000FF;">(</span><span style="color: #000000;">refresh_cache</span><span style="color: #0000FF;">)</span> |
|||
"|+ As of { Date.today } :: Tasks: { $taskcnt } :: Draft Tasks: { $draftcnt } :: Total: { $count }\n", |
|||
<span style="color: #008080;">elsif</span> <span style="color: #7060A8;">get_file_size</span><span style="color: #0000FF;">(</span><span style="color: #000000;">filename</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> |
|||
"! Count !! Task !! Category" |
|||
<span style="color: #000000;">why</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"filesize of 0"</span> |
|||
; |
|||
<span style="color: #008080;">else</span> |
|||
<span style="color: #000000;">text</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">trim</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">get_text</span><span style="color: #0000FF;">(</span><span style="color: #000000;">filename</span><span style="color: #0000FF;">))</span> |
|||
# Sort tasks by count then add row |
|||
<span style="color: #008080;">if</span> <span style="color: #008080;">not</span> <span style="color: #004080;">sequence</span><span style="color: #0000FF;">(</span><span style="color: #000000;">text</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span> |
|||
for %tasks.sort: -*.value<count> -> $task { |
|||
<span style="color: #000000;">why</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"no text"</span> |
|||
$out.say: |
|||
<span style="color: #008080;">elsif</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">text</span><span style="color: #0000FF;">)<</span><span style="color: #000000;">10</span> <span style="color: #008080;">then</span> |
|||
"|-\n", |
|||
<span style="color: #000000;">why</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"<10 bytes"</span> |
|||
"| { $task.value<count> }\n", |
|||
<span style="color: #008080;">else</span> |
|||
( $task.key ~~ /\d/ |
|||
<span style="color: #000000;">refetch</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">false</span> |
|||
?? "|data-sort-value=\"{ $task.key.&naturally }\"| { $task.key }\n" |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
|||
!! "| { $task.key }\n" |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
|||
), |
|||
" |
<span style="color: #008080;">else</span> |
||
<span style="color: #000000;">refetch</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">true</span> |
|||
} |
|||
<span style="color: #004080;">string</span> <span style="color: #000000;">directory</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">get_file_path</span><span style="color: #0000FF;">(</span><span style="color: #000000;">filename</span><span style="color: #0000FF;">)</span> |
|||
<span style="color: #008080;">if</span> <span style="color: #7060A8;">get_file_type</span><span style="color: #0000FF;">(</span><span style="color: #000000;">directory</span><span style="color: #0000FF;">)!=</span><span style="color: #004600;">FILETYPE_DIRECTORY</span> <span style="color: #008080;">then</span> |
|||
$out.say( "|}\n", '</div>' ); |
|||
<span style="color: #008080;">if</span> <span style="color: #008080;">not</span> <span style="color: #000000;">create_directory</span><span style="color: #0000FF;">(</span><span style="color: #000000;">directory</span><span style="color: #0000FF;">,</span><span style="color: #000000;">make_parent</span><span style="color: #0000FF;">:=</span><span style="color: #004600;">true</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span> |
|||
$out.close; |
|||
<span style="color: #7060A8;">crash</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"cannot create %s directory"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">directory</span><span style="color: #0000FF;">})</span> |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
|||
note "Table file saved as: {$tablefile.IO.absolute}"; |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
|||
sub mediawiki-query ($site, $type, *%query) { |
|||
<span style="color: #008080;">if</span> <span style="color: #000000;">refetch</span> <span style="color: #008080;">then</span> |
|||
my $url = "$site/api.php?" ~ uri-query-string( |
|||
<span style="color: #000000;">wastitle</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"x"</span> <span style="color: #000080;font-style:italic;">-- don't clobber</span> |
|||
:action<query>, :format<json>, :formatversion<2>, |%query); |
|||
<span style="color: #004080;">string</span> <span style="color: #000000;">nofn</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">?</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"(%d/%d, %.1f%%) "</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span><span style="color: #000000;">i</span><span style="color: #0000FF;">/</span><span style="color: #000000;">n</span><span style="color: #0000FF;">*</span><span style="color: #000000;">100</span><span style="color: #0000FF;">}):</span><span style="color: #008000;">""</span><span style="color: #0000FF;">),</span> |
|||
my $continue = ''; |
|||
<span style="color: #000000;">title</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"Downloading %s%s (%s)..."</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">nofn</span><span style="color: #0000FF;">,</span><span style="color: #000000;">html_clean</span><span style="color: #0000FF;">(</span><span style="color: #000000;">filename</span><span style="color: #0000FF;">),</span><span style="color: #000000;">why</span><span style="color: #0000FF;">})</span> |
|||
<span style="color: #000000;">show_title</span><span style="color: #0000FF;">(</span><span style="color: #000000;">title</span><span style="color: #0000FF;">)</span> |
|||
gather loop { |
|||
<span style="color: #008080;">if</span> <span style="color: #000000;">curl</span><span style="color: #0000FF;">=</span><span style="color: #004600;">NULL</span> <span style="color: #008080;">then</span> |
|||
my $response = $client.get("$url&$continue"); |
|||
<span style="color: #7060A8;">curl_global_init</span><span style="color: #0000FF;">()</span> |
|||
my $data = from-json($response.content); |
|||
<span style="color: #000000;">curl</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">curl_easy_init</span><span style="color: #0000FF;">()</span> |
|||
take $_ for $data.<query>.{$type}.values; |
|||
<span style="color: #000000;">pErrorBuffer</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">allocate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">CURL_ERROR_SIZE</span><span style="color: #0000FF;">)</span> |
|||
$continue = uri-query-string |($data.<query-continue>{*}».hash.hash or last); |
|||
<span style="color: #7060A8;">curl_easy_setopt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">curl</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">CURLOPT_ERRORBUFFER</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">pErrorBuffer</span><span style="color: #0000FF;">)</span> |
|||
} |
|||
<span style="color: #7060A8;">curl_easy_setopt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">curl</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">CURLOPT_WRITEFUNCTION</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">write_cb</span><span style="color: #0000FF;">)</span> |
|||
} |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
|||
<span style="color: #000000;">url</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">url</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%3A"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">":"</span><span style="color: #0000FF;">)</span> |
|||
sub uri-query-string (*%fields) { %fields.map({ "{.key}={uri-escape .value}" }).join("&") } |
|||
<span style="color: #000000;">url</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">url</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%2A"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"*"</span><span style="color: #0000FF;">)</span> |
|||
<span style="color: #7060A8;">curl_easy_setopt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">curl</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">CURLOPT_URL</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">url</span><span style="color: #0000FF;">)</span> |
|||
sub naturally ($a) { $a.lc.subst(/(\d+)/, ->$/ {0~(65+$0.chars).chr~$0},:g) } |
|||
<span style="color: #004080;">integer</span> <span style="color: #000000;">fn</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">open</span><span style="color: #0000FF;">(</span><span style="color: #000000;">filename</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"wb"</span><span style="color: #0000FF;">)</span> |
|||
</lang> |
|||
<span style="color: #7060A8;">assert</span><span style="color: #0000FF;">(</span><span style="color: #000000;">fn</span><span style="color: #0000FF;">!=-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"cannot open "</span><span style="color: #0000FF;">&</span><span style="color: #000000;">filename</span><span style="color: #0000FF;">)</span> |
|||
{{out}} |
|||
<span style="color: #7060A8;">curl_easy_setopt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">curl</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">CURLOPT_WRITEDATA</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">fn</span><span style="color: #0000FF;">)</span> |
|||
<div style="height:80ex;overflow:scroll;"> |
|||
<span style="color: #008080;">while</span> <span style="color: #004600;">true</span> <span style="color: #008080;">do</span> |
|||
{|class="wikitable sortable" |
|||
<span style="color: #004080;">CURLcode</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">curl_easy_perform</span><span style="color: #0000FF;">(</span><span style="color: #000000;">curl</span><span style="color: #0000FF;">)</span> |
|||
|+ As of 2018-03-29 :: Tasks: 871 :: Draft Tasks: 209 :: Total: 1080 |
|||
<span style="color: #008080;">if</span> <span style="color: #000000;">res</span><span style="color: #0000FF;">=</span><span style="color: #004600;">CURLE_OK</span> <span style="color: #008080;">then</span> <span style="color: #008080;">exit</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
|||
! Count !! Task !! Category |
|||
<span style="color: #004080;">string</span> <span style="color: #000000;">error</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%d"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">res</span><span style="color: #0000FF;">)</span> |
|||
|- |
|||
<span style="color: #008080;">if</span> <span style="color: #000000;">res</span><span style="color: #0000FF;">=</span><span style="color: #000000;">CURLE_COULDNT_RESOLVE_HOST</span> <span style="color: #008080;">then</span> |
|||
| 383 |
|||
<span style="color: #000000;">error</span> <span style="color: #0000FF;">&=</span> <span style="color: #008000;">" [CURLE_COULDNT_RESOLVE_HOST]"</span> |
|||
| Hello world/Text |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
|||
| Task |
|||
<span style="color: #7060A8;">progress</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"Error %s downloading file, retry?(Y/N):"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">error</span><span style="color: #0000FF;">})</span> |
|||
|- |
|||
<span style="color: #008080;">if</span> <span style="color: #7060A8;">lower</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">wait_key</span><span style="color: #0000FF;">())!=</span><span style="color: #008000;">'y'</span> <span style="color: #008080;">then</span> <span style="color: #7060A8;">abort</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
|||
| 288 |
|||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Y\n"</span><span style="color: #0000FF;">)</span> |
|||
|data-sort-value="0C99 bottles of beer"| 99 Bottles of Beer |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span> |
|||
| Task |
|||
<span style="color: #7060A8;">close</span><span style="color: #0000FF;">(</span><span style="color: #000000;">fn</span><span style="color: #0000FF;">)</span> |
|||
|- |
|||
<span style="color: #000000;">refresh_cache</span> <span style="color: #0000FF;">+=</span> <span style="color: #7060A8;">timedelta</span><span style="color: #0000FF;">(</span><span style="color: #000000;">days</span><span style="color: #0000FF;">:=</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- did I mention it is slow?</span> |
|||
| 266 |
|||
<span style="color: #000000;">text</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">get_text</span><span style="color: #0000FF;">(</span><span style="color: #000000;">filename</span><span style="color: #0000FF;">)</span> |
|||
| FizzBuzz |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
|||
| Task |
|||
<span style="color: #008080;">return</span> <span style="color: #000000;">text</span> |
|||
|- |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span> |
|||
| 265 |
|||
|data-sort-value="0D100 doors"| 100 doors |
|||
<span style="color: #008080;">global</span> <span style="color: #008080;">function</span> <span style="color: #000000;">open_category</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">filename</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span><span style="color: #0000FF;">)</span> |
|||
| Task |
|||
<span style="color: #008080;">return</span> <span style="color: #000000;">open_download</span><span style="color: #0000FF;">(</span><span style="color: #000000;">filename</span><span style="color: #0000FF;">&</span><span style="color: #008000;">".htm"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"http://rosettacode.org/wiki/Category:"</span><span style="color: #0000FF;">&</span><span style="color: #000000;">filename</span><span style="color: #0000FF;">,</span><span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">)</span> |
|||
|- |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span> |
|||
| 244 |
|||
| Fibonacci sequence |
|||
<span style="color: #008080;">global</span> <span style="color: #008080;">function</span> <span style="color: #000000;">dewiki</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">sequence</span> <span style="color: #000000;">exclude</span><span style="color: #0000FF;">={})</span> |
|||
| Task |
|||
<span style="color: #000080;font-style:italic;">-- extract tasks from eg `<li><a href="/wiki/100_doors"`</span> |
|||
|- |
|||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">tasks</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span> |
|||
| 242 |
|||
<span style="color: #004080;">integer</span> <span style="color: #000000;">start</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">finish</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">match</span><span style="color: #0000FF;">(</span><span style="color: #008000;">`<div class="printfooter">`</span><span style="color: #0000FF;">,</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span> |
|||
| Comments |
|||
<span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">..</span><span style="color: #000000;">finish</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> |
|||
| Task |
|||
<span style="color: #008080;">while</span> <span style="color: #004600;">true</span> <span style="color: #008080;">do</span> |
|||
|- |
|||
<span style="color: #000000;">start</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">match</span><span style="color: #0000FF;">(</span><span style="color: #008000;">`<li><a href="/wiki/`</span><span style="color: #0000FF;">,</span><span style="color: #000000;">s</span><span style="color: #0000FF;">,</span><span style="color: #000000;">start</span><span style="color: #0000FF;">)</span> |
|||
| 236 |
|||
<span style="color: #008080;">if</span> <span style="color: #000000;">start</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #008080;">exit</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
|||
| Factorial |
|||
<span style="color: #000000;">start</span> <span style="color: #0000FF;">+=</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #008000;">`<li><a href="/wiki/`</span><span style="color: #0000FF;">)</span> |
|||
| Task |
|||
<span style="color: #000000;">finish</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #008000;">'"'</span><span style="color: #0000FF;">,</span><span style="color: #000000;">s</span><span style="color: #0000FF;">,</span><span style="color: #000000;">start</span><span style="color: #0000FF;">)</span> |
|||
|- |
|||
<span style="color: #004080;">string</span> <span style="color: #000000;">task</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">start</span><span style="color: #0000FF;">..</span><span style="color: #000000;">finish</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> |
|||
| 224 |
|||
<span style="color: #000000;">task</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute_all</span><span style="color: #0000FF;">(</span><span style="color: #000000;">task</span><span style="color: #0000FF;">,{</span><span style="color: #008000;">"*"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">":"</span><span style="color: #0000FF;">},{</span><span style="color: #008000;">"%2A"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%3A"</span><span style="color: #0000FF;">})</span> |
|||
| A+B |
|||
<span style="color: #000000;">tasks</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">append</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tasks</span><span style="color: #0000FF;">,</span><span style="color: #000000;">task</span><span style="color: #0000FF;">)</span> |
|||
| Task |
|||
<span style="color: #000000;">start</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">finish</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span> |
|||
|- |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span> |
|||
| 215 |
|||
<span style="color: #008080;">return</span> <span style="color: #000000;">tasks</span> |
|||
| Empty program |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span> |
|||
| Task |
|||
|- |
|||
<span style="color: #008080;">global</span> <span style="color: #008080;">procedure</span> <span style="color: #000000;">curl_cleanup</span><span style="color: #0000FF;">()</span> |
|||
| 208 |
|||
<span style="color: #008080;">if</span> <span style="color: #000000;">curl</span><span style="color: #0000FF;">!=</span><span style="color: #004600;">NULL</span> <span style="color: #008080;">then</span> |
|||
| Function definition |
|||
<span style="color: #7060A8;">curl_easy_cleanup</span><span style="color: #0000FF;">(</span><span style="color: #000000;">curl</span><span style="color: #0000FF;">)</span> |
|||
| Task |
|||
<span style="color: #7060A8;">free</span><span style="color: #0000FF;">(</span><span style="color: #000000;">pErrorBuffer</span><span style="color: #0000FF;">)</span> |
|||
|- |
|||
<span style="color: #000000;">curl</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">NULL</span> |
|||
| 196 |
|||
<span style="color: #000000;">pErrorBuffer</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">NULL</span> |
|||
| Loops/For |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
|||
| Task |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span> |
|||
|- |
|||
<!--</syntaxhighlight>--> |
|||
| 195 |
|||
The task itself: |
|||
| Loops/Infinite |
|||
<!--<syntaxhighlight lang="phix">(notonline)--> |
|||
| Task |
|||
<span style="color: #000080;font-style:italic;">-- |
|||
|- |
|||
-- demo\rosetta\Count_examples.exw |
|||
| 194 |
|||
-- =============================== |
|||
| Ackermann function |
|||
-- |
|||
| Task |
|||
-- (This uses a few '&' instead of/as well as 'a', fairly obviously for everyone's sanity..) |
|||
|- |
|||
-- Counts no of "<nowiki>{{</nowiki>he&der|" (nb not "==<nowiki>{{</nowiki>he&der|") via web api (but gets tasks via scraping). |
|||
| 190 |
|||
-- Since downloading all the pages can be very slow, this uses a cache. |
|||
| Loops/While |
|||
-- Limiting (notdone) by "Phix" fairly obviously speeds it up tenfold :-) |
|||
| Task |
|||
--</span> |
|||
|- |
|||
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (fairly obviously this will never ever run in a browser!)</span> |
|||
| 187 |
|||
<span style="color: #008080;">constant</span> <span style="color: #000000;">include_drafts</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">true</span><span style="color: #0000FF;">,</span> |
|||
| Arrays |
|||
<span style="color: #000000;">sort_by_count</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">false</span><span style="color: #0000FF;">,</span> |
|||
| Task |
|||
<span style="color: #000080;font-style:italic;">-- notlang = "Phix" -- or "" (ie a zero length string) for all</span> |
|||
|- |
|||
<span style="color: #000000;">notlang</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">""</span> |
|||
| 185 |
|||
| Reverse a string |
|||
<span style="color: #008080;">include</span> <span style="color: #000000;">rosettacode_cache</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> |
|||
| Task |
|||
|- |
|||
<span style="color: #008080;">function</span> <span style="color: #000000;">count_tasks</span><span style="color: #0000FF;">()</span> |
|||
| 174 |
|||
<span style="color: #008080;">if</span> <span style="color: #7060A8;">get_file_type</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"rc_cache"</span><span style="color: #0000FF;">)!=</span><span style="color: #004600;">FILETYPE_DIRECTORY</span> <span style="color: #008080;">then</span> |
|||
| Arithmetic/Integer |
|||
<span style="color: #008080;">if</span> <span style="color: #008080;">not</span> <span style="color: #000000;">create_directory</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"rc_cache"</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span> |
|||
| Task |
|||
<span style="color: #7060A8;">crash</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"cannot create rc_cache directory"</span><span style="color: #0000FF;">)</span> |
|||
|- |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
|||
| 173 |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
|||
| Greatest common divisor |
|||
<span style="color: #000080;font-style:italic;">-- note this lot use web scraping (as cribbed from a similar task) ...</span> |
|||
| Task |
|||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">tasks</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">dewiki</span><span style="color: #0000FF;">(</span><span style="color: #000000;">open_category</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"Programming_Tasks"</span><span style="color: #0000FF;">))</span> |
|||
|- |
|||
<span style="color: #008080;">if</span> <span style="color: #000000;">include_drafts</span> <span style="color: #008080;">then</span> |
|||
| 172 |
|||
<span style="color: #000000;">tasks</span> <span style="color: #0000FF;">&=</span> <span style="color: #000000;">dewiki</span><span style="color: #0000FF;">(</span><span style="color: #000000;">open_category</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"Draft_Programming_Tasks"</span><span style="color: #0000FF;">))</span> |
|||
| Conditional structures |
|||
<span style="color: #000000;">tasks</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sort</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tasks</span><span style="color: #0000FF;">)</span> |
|||
| Task |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
|||
|- |
|||
<span style="color: #008080;">if</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">notlang</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span> |
|||
| 171 |
|||
<span style="color: #000080;font-style:italic;">-- filter already done in specified language</span> |
|||
| Greatest element of a list |
|||
<span style="color: #004080;">string</span> <span style="color: #000000;">langurl</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"http://rosettacode.org/wiki/Category:"</span><span style="color: #0000FF;">&</span><span style="color: #000000;">notlang</span> |
|||
| Task |
|||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">done</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">dewiki</span><span style="color: #0000FF;">(</span><span style="color: #000000;">open_download</span><span style="color: #0000FF;">(</span><span style="color: #000000;">notlang</span><span style="color: #0000FF;">&</span><span style="color: #008000;">".htm"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">langurl</span><span style="color: #0000FF;">))</span> |
|||
|- |
|||
<span style="color: #004080;">integer</span> <span style="color: #000000;">k</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span> |
|||
| 167 |
|||
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tasks</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span> |
|||
| Averages/Arithmetic mean |
|||
<span style="color: #004080;">string</span> <span style="color: #000000;">ti</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">tasks</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span> |
|||
| Task |
|||
<span style="color: #004080;">integer</span> <span style="color: #000000;">d</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ti</span><span style="color: #0000FF;">,</span><span style="color: #000000;">done</span><span style="color: #0000FF;">)</span> |
|||
|- |
|||
<span style="color: #008080;">if</span> <span style="color: #008080;">not</span> <span style="color: #000000;">d</span> <span style="color: #008080;">then</span> |
|||
| 164 |
|||
<span style="color: #000000;">k</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span> |
|||
| Integer comparison |
|||
<span style="color: #000000;">tasks</span><span style="color: #0000FF;">[</span><span style="color: #000000;">k</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">ti</span> |
|||
| Task |
|||
<span style="color: #008080;">else</span> |
|||
|- |
|||
<span style="color: #000000;">done</span><span style="color: #0000FF;">[</span><span style="color: #000000;">d</span><span style="color: #0000FF;">..</span><span style="color: #000000;">d</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span> |
|||
| 161 |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
|||
| Increment a numerical string |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span> |
|||
| Task |
|||
<span style="color: #000000;">tasks</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">tasks</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">..</span><span style="color: #000000;">k</span><span style="color: #0000FF;">]</span> |
|||
|- |
|||
<span style="color: #000000;">done</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span> |
|||
| 160 |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
|||
| Loops/For with a specified step |
|||
<span style="color: #7060A8;">progress</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%d tasks found\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tasks</span><span style="color: #0000FF;">)})</span> |
|||
| Task |
|||
<span style="color: #000080;font-style:italic;">-- ... whereas the individual tasks use the web api instead (3x smaller/faster)</span> |
|||
|- |
|||
<span style="color: #004080;">integer</span> <span style="color: #000000;">total_count</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span> |
|||
| 159 |
|||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">task_counts</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tasks</span><span style="color: #0000FF;">))</span> |
|||
| Loops/Downward for |
|||
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tasks</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span> |
|||
| Task |
|||
<span style="color: #004080;">string</span> <span style="color: #000000;">ti</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">tasks</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">],</span> |
|||
|- |
|||
<span style="color: #000000;">url</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"http://rosettacode.org/mw/index.php?title=%s&action=raw"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">ti</span><span style="color: #0000FF;">}),</span> |
|||
| 159 |
|||
<span style="color: #000000;">contents</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">open_download</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ti</span><span style="color: #0000FF;">&</span><span style="color: #008000;">".raw"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">url</span><span style="color: #0000FF;">),</span> |
|||
| Array concatenation |
|||
<span style="color: #000000;">prev</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">""</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">curr</span> |
|||
| Task |
|||
<span style="color: #004080;">integer</span> <span style="color: #000000;">count</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">start</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span> |
|||
|- |
|||
<span style="color: #008080;">while</span> <span style="color: #004600;">true</span> <span style="color: #008080;">do</span> |
|||
| 158 |
|||
<span style="color: #000000;">start</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">match</span><span style="color: #0000FF;">(</span><span style="color: #008000;">`<nowiki>{{</nowiki>hea`</span><span style="color: #0000FF;">&</span><span style="color: #008000;">`der|`</span><span style="color: #0000FF;">,</span><span style="color: #000000;">contents</span><span style="color: #0000FF;">,</span><span style="color: #000000;">start</span><span style="color: #0000FF;">)</span> |
|||
| Repeat a string |
|||
<span style="color: #008080;">if</span> <span style="color: #000000;">start</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #008080;">exit</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
|||
| Task |
|||
<span style="color: #000080;font-style:italic;">-- |
|||
|- |
|||
-- skip duplicates/we also have to cope with eg |
|||
| 156 |
|||
-- ==<nowiki>{{</nowiki>he&der|Python<nowiki>}}</nowiki>== \ |
|||
| Loops/Foreach |
|||
-- ===<nowiki>{{</nowiki>he&der|Python<nowiki>}}</nowiki> Original=== } count |
|||
| Task |
|||
-- ===<nowiki>{{</nowiki>he&der|Python<nowiki>}}</nowiki> Succinct=== } once |
|||
|- |
|||
-- ===<nowiki>{{</nowiki>he&der|Python<nowiki>}}</nowiki> Recursive === / |
|||
| 155 |
|||
-- ==<nowiki>{{</nowiki>he&der|Mathematica<nowiki>}}</nowiki> / <nowiki>{{</nowiki>he&der|Wolfram Language<nowiki>}}</nowiki>== \ |
|||
| Copy a string |
|||
-- ==<nowiki>{{</nowiki>he&der|Icon<nowiki>}}</nowiki> and <nowiki>{{</nowiki>he&der|Unicon<nowiki>}}</nowiki>== } count |
|||
| Task |
|||
-- == <nowiki>{{</nowiki>he&der|Icon<nowiki>}}</nowiki> and <nowiki>{{</nowiki>he&der|Unicon<nowiki>}}</nowiki> == / both |
|||
|- |
|||
-- == <nowiki>{{</nowiki>he&der|Java<nowiki>}}</nowiki>== |
|||
| 155 |
|||
-- etc. Note however that this /does/ count eg |
|||
| Boolean values |
|||
-- ===<nowiki>{{</nowiki>he&der|Applesoft BASIC<nowiki>}}</nowiki>=== \ |
|||
| Task |
|||
-- ===<nowiki>{{</nowiki>he&der|BASIC256<nowiki>}}</nowiki>=== } count |
|||
|- |
|||
-- ===<nowiki>{{</nowiki>he&der|Commodore BASIC<nowiki>}}</nowiki>=== } 'em |
|||
| 150 |
|||
-- ===<nowiki>{{</nowiki>he&der|IS-BASIC<nowiki>}}</nowiki>=== } all |
|||
| Hello world/Graphical |
|||
-- ===<nowiki>{{</nowiki>he&der|Sinclair ZX81 BASIC<nowiki>}}</nowiki>=== / |
|||
| Task |
|||
--</span> |
|||
|- |
|||
<span style="color: #000000;">curr</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">contents</span><span style="color: #0000FF;">[</span><span style="color: #000000;">start</span><span style="color: #0000FF;">..</span><span style="color: #7060A8;">match</span><span style="color: #0000FF;">(</span><span style="color: #008000;">`<nowiki>}}</nowiki>`</span><span style="color: #0000FF;">,</span><span style="color: #000000;">contents</span><span style="color: #0000FF;">,</span><span style="color: #000000;">start</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)]</span> |
|||
| 149 |
|||
<span style="color: #008080;">if</span> <span style="color: #000000;">curr</span><span style="color: #0000FF;">!=</span><span style="color: #000000;">prev</span> <span style="color: #008080;">then</span> |
|||
| Sum and product of an array |
|||
<span style="color: #000000;">count</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span> |
|||
| Task |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
|||
|- |
|||
<span style="color: #000000;">prev</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">curr</span> |
|||
| 148 |
|||
<span style="color: #000000;">start</span> <span style="color: #0000FF;">+=</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #008000;">`<nowiki>{{</nowiki>hea`</span><span style="color: #0000FF;">&</span><span style="color: #008000;">`der|`</span><span style="color: #0000FF;">)</span> |
|||
| String length |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span> |
|||
| Task |
|||
<span style="color: #008080;">if</span> <span style="color: #000000;">sort_by_count</span> <span style="color: #008080;">then</span> |
|||
|- |
|||
<span style="color: #000000;">task_counts</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">count</span> |
|||
| 148 |
|||
<span style="color: #008080;">elsif</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">notlang</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">or</span> <span style="color: #000000;">i</span><span style="color: #0000FF;"><=</span><span style="color: #000000;">2</span> <span style="color: #008080;">or</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">>=</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tasks</span><span style="color: #0000FF;">)-</span><span style="color: #000000;">1</span> <span style="color: #008080;">or</span> <span style="color: #7060A8;">mod</span><span style="color: #0000FF;">(</span><span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #000000;">200</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> |
|||
| Even or odd |
|||
<span style="color: #7060A8;">progress</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%s: %d\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">html_clean</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ti</span><span style="color: #0000FF;">),</span><span style="color: #000000;">count</span><span style="color: #0000FF;">})</span> |
|||
| Task |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
|||
|- |
|||
<span style="color: #000000;">total_count</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">count</span> |
|||
| 148 |
|||
<span style="color: #008080;">if</span> <span style="color: #7060A8;">get_key</span><span style="color: #0000FF;">()=</span><span style="color: #000000;">#1B</span> <span style="color: #008080;">then</span> <span style="color: #7060A8;">progress</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"escape keyed\n"</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">exit</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
|||
| String case |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span> |
|||
| Task |
|||
<span style="color: #000000;">curl_cleanup</span><span style="color: #0000FF;">()</span> |
|||
|- |
|||
<span style="color: #008080;">if</span> <span style="color: #000000;">sort_by_count</span> <span style="color: #008080;">then</span> |
|||
| 146 |
|||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">tags</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">custom_sort</span><span style="color: #0000FF;">(</span><span style="color: #000000;">task_counts</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tasks</span><span style="color: #0000FF;">)))</span> |
|||
| Hailstone sequence |
|||
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tags</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">to</span> <span style="color: #000000;">1</span> <span style="color: #008080;">by</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">1</span> <span style="color: #008080;">do</span> |
|||
| Task |
|||
<span style="color: #004080;">integer</span> <span style="color: #000000;">ti</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">tags</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span> |
|||
|- |
|||
<span style="color: #7060A8;">progress</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%s: %d\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">html_clean</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tasks</span><span style="color: #0000FF;">[</span><span style="color: #000000;">ti</span><span style="color: #0000FF;">]),</span><span style="color: #000000;">task_counts</span><span style="color: #0000FF;">[</span><span style="color: #000000;">ti</span><span style="color: #0000FF;">]})</span> |
|||
| 146 |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span> |
|||
| Character codes |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
|||
| Task |
|||
<span style="color: #008080;">return</span> <span style="color: #000000;">total_count</span> |
|||
|- |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span> |
|||
| 144 |
|||
| Loops/Do-while |
|||
<span style="color: #7060A8;">progress</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"Total: %d\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">count_tasks</span><span style="color: #0000FF;">()})</span> |
|||
| Task |
|||
<!--</syntaxhighlight>--> |
|||
|- |
|||
{{out}} (as of 30/2/22, showing first two, every 200th, and last two) |
|||
| 144 |
|||
<pre> |
|||
| Apply a callback to an array |
|||
1523 tasks found |
|||
| Task |
|||
10001th prime: 33 |
|||
|- |
|||
100 doors: 337 |
|||
| 141 |
|||
Chowla numbers: 46 |
|||
| Hello world/Newline omission |
|||
Exactly three adjacent 3 in lists: 27 |
|||
| Task |
|||
Imaginary base numbers: 21 |
|||
|- |
|||
Monte Carlo methods: 87 |
|||
| 140 |
|||
Prime numbers which contain 123: 23 |
|||
| String concatenation |
|||
Smallest number k such that k+2^m is composite for all m less than k: 5 |
|||
| Task |
|||
Trabb Pardo-Knuth algorithm: 83 |
|||
|- |
|||
Zig-zag matrix: 113 |
|||
| 139 |
|||
Zumkeller numbers: 36 |
|||
| Loops/N plus one half |
|||
Total: 88455 |
|||
| Task |
|||
</pre> |
|||
|- |
|||
| 138 |
|||
| Binary digits |
|||
| Task |
|||
|- |
|||
| 138 |
|||
| Sum of a series |
|||
| Task |
|||
|- |
|||
| 138 |
|||
| Tokenize a string |
|||
| Task |
|||
|- |
|||
| 137 |
|||
| Loops/Break |
|||
| Task |
|||
|- |
|||
| 137 |
|||
| Palindrome detection |
|||
| Task |
|||
|- |
|||
| 137 |
|||
| Filter |
|||
| Task |
|||
|- |
|||
| 137 |
|||
| Sum of squares |
|||
| Task |
|||
|- |
|||
| 137 |
|||
| Generic swap |
|||
| Task |
|||
|- |
|||
| 136 |
|||
| Integer sequence |
|||
| Task |
|||
|- |
|||
| 136 |
|||
|data-sort-value="rot-0C13"| Rot-13 |
|||
| Task |
|||
|- |
|||
| 136 |
|||
| Logical operations |
|||
| Task |
|||
|- |
|||
| 135 |
|||
| Execute a system command |
|||
| Task |
|||
|- |
|||
| 134 |
|||
| Sieve of Eratosthenes |
|||
| Task |
|||
|- |
|||
| 133 |
|||
| Towers of Hanoi |
|||
| Task |
|||
|- |
|||
| 131 |
|||
| Sort an integer array |
|||
| Task |
|||
|- |
|||
| 130 |
|||
| Dot product |
|||
| Task |
|||
|- |
|||
| 129 |
|||
| File input/output |
|||
| Task |
|||
|- |
|||
| 129 |
|||
| Leap year |
|||
| Task |
|||
|- |
|||
| 127 |
|||
| Associative array/Creation |
|||
| Task |
|||
|- |
|||
| 126 |
|||
| Sorting algorithms/Bubble sort |
|||
| Task |
|||
|- |
|||
| 126 |
|||
| Higher-order functions |
|||
| Task |
|||
|- |
|||
| 126 |
|||
| Remove duplicate elements |
|||
| Task |
|||
|- |
|||
| 125 |
|||
| Determine if a string is numeric |
|||
| Task |
|||
|- |
|||
| 124 |
|||
| Array length |
|||
| Task |
|||
|- |
|||
| 123 |
|||
| User input/Text |
|||
| Task |
|||
|- |
|||
| 123 |
|||
| Quine |
|||
| Task |
|||
|- |
|||
| 123 |
|||
| Hello world/Standard error |
|||
| Task |
|||
|- |
|||
| 123 |
|||
| Empty string |
|||
| Task |
|||
|- |
|||
| 122 |
|||
| Guess the number |
|||
| Task |
|||
|- |
|||
| 122 |
|||
| Read entire file |
|||
| Task |
|||
|- |
|||
| 121 |
|||
| Command-line arguments |
|||
| Task |
|||
|- |
|||
| 121 |
|||
| Roman numerals/Encode |
|||
| Task |
|||
|- |
|||
| 120 |
|||
| Create a file |
|||
| Task |
|||
|- |
|||
| 120 |
|||
| Loops/Continue |
|||
| Task |
|||
|- |
|||
| 119 |
|||
| Primality by trial division |
|||
| Task |
|||
|- |
|||
| 118 |
|||
| Loop over multiple arrays simultaneously |
|||
| Task |
|||
|- |
|||
| 118 |
|||
| Ethiopian multiplication |
|||
| Task |
|||
|- |
|||
| 118 |
|||
| Bitwise operations |
|||
| Task |
|||
|- |
|||
| 117 |
|||
| Sleep |
|||
| Task |
|||
|- |
|||
| 117 |
|||
| Least common multiple |
|||
| Task |
|||
|- |
|||
| 116 |
|||
| Sorting algorithms/Quicksort |
|||
| Task |
|||
|- |
|||
| 116 |
|||
| System time |
|||
| Task |
|||
|- |
|||
| 116 |
|||
| Day of the week |
|||
| Task |
|||
|- |
|||
| 116 |
|||
| Factors of an integer |
|||
| Task |
|||
|- |
|||
| 115 |
|||
| Substring |
|||
| Task |
|||
|- |
|||
| 115 |
|||
| Check that file exists |
|||
| Task |
|||
|- |
|||
| 115 |
|||
| Happy numbers |
|||
| Task |
|||
|- |
|||
| 115 |
|||
| Include a file |
|||
| Task |
|||
|- |
|||
| 114 |
|||
| Caesar cipher |
|||
| Task |
|||
|- |
|||
| 114 |
|||
| Literals/String |
|||
| Task |
|||
|- |
|||
| 113 |
|||
| Literals/Integer |
|||
| Task |
|||
|- |
|||
| 113 |
|||
| Mutual recursion |
|||
| Task |
|||
|- |
|||
| 112 |
|||
| Pascal's triangle |
|||
| Task |
|||
|- |
|||
| 112 |
|||
| Detect division by zero |
|||
| Task |
|||
|- |
|||
| 111 |
|||
| Luhn test of credit card numbers |
|||
| Task |
|||
|- |
|||
| 111 |
|||
| Flatten a list |
|||
| Task |
|||
|- |
|||
| 111 |
|||
| Averages/Root mean square |
|||
| Task |
|||
|- |
|||
| 111 |
|||
| Balanced brackets |
|||
| Task |
|||
|- |
|||
| 110 |
|||
| Stack |
|||
| Task |
|||
|- |
|||
| 110 |
|||
| Program termination |
|||
| Task |
|||
|- |
|||
| 109 |
|||
| Knuth shuffle |
|||
| Task |
|||
|- |
|||
| 109 |
|||
| File size |
|||
| Task |
|||
|- |
|||
| 108 |
|||
| Variables |
|||
| Task |
|||
|- |
|||
| 108 |
|||
| Compound data type |
|||
| Task |
|||
|- |
|||
| 107 |
|||
| Read a file line by line |
|||
| Task |
|||
|- |
|||
| 107 |
|||
| Associative array/Iteration |
|||
| Task |
|||
|- |
|||
| 107 |
|||
| Date format |
|||
| Task |
|||
|- |
|||
| 106 |
|||
| Rename a file |
|||
| Task |
|||
|- |
|||
| 106 |
|||
| Search a list |
|||
| Task |
|||
|- |
|||
| 106 |
|||
| Generate lower case ASCII alphabet |
|||
| Task |
|||
|- |
|||
| 106 |
|||
| Real constants and functions |
|||
| Task |
|||
|- |
|||
| 106 |
|||
| Delete a file |
|||
| Task |
|||
|- |
|||
| 105 |
|||
| Mandelbrot set |
|||
| Task |
|||
|- |
|||
| 104 |
|||
| Count in octal |
|||
| Task |
|||
|- |
|||
| 104 |
|||
| Return multiple values |
|||
| Task |
|||
|- |
|||
| 104 |
|||
| ABC Problem |
|||
| Task |
|||
|- |
|||
| 104 |
|||
| Input loop |
|||
| Task |
|||
|- |
|||
| 104 |
|||
| Function composition |
|||
| Task |
|||
|- |
|||
| 104 |
|||
| Null object |
|||
| Task |
|||
|- |
|||
| 103 |
|||
| Loops/Nested |
|||
| Task |
|||
|- |
|||
| 103 |
|||
| Classes |
|||
| Task |
|||
|- |
|||
| 103 |
|||
| Sorting algorithms/Insertion sort |
|||
| Task |
|||
|- |
|||
| 103 |
|||
| Case-sensitivity of identifiers |
|||
| Task |
|||
|- |
|||
| 103 |
|||
| Binary search |
|||
| Task |
|||
|- |
|||
| 103 |
|||
| Formatted numeric output |
|||
| Task |
|||
|- |
|||
| 102 |
|||
| Averages/Median |
|||
| Task |
|||
|- |
|||
| 102 |
|||
| Hostname |
|||
| Task |
|||
|- |
|||
| 102 |
|||
| Count occurrences of a substring |
|||
| Task |
|||
|- |
|||
| 101 |
|||
| Hash from two arrays |
|||
| Task |
|||
|- |
|||
| 101 |
|||
| Arithmetic/Complex |
|||
| Task |
|||
|- |
|||
| 101 |
|||
| Random numbers |
|||
| Task |
|||
|- |
|||
| 100 |
|||
| Pick random element |
|||
| Task |
|||
|- |
|||
| 100 |
|||
| Multiplication tables |
|||
| Task |
|||
|- |
|||
| 100 |
|||
| HTTP |
|||
| Task |
|||
|- |
|||
| 99 |
|||
| Pangram checker |
|||
| Task |
|||
|- |
|||
| 99 |
|||
| Matrix multiplication |
|||
| Task |
|||
|- |
|||
| 99 |
|||
| Matrix transposition |
|||
| Task |
|||
|- |
|||
| 99 |
|||
| N-queens problem |
|||
| Task |
|||
|- |
|||
| 99 |
|||
| Find limit of recursion |
|||
| Task |
|||
|- |
|||
| 99 |
|||
| Anagrams |
|||
| Task |
|||
|- |
|||
| 99 |
|||
| Environment variables |
|||
| Task |
|||
|- |
|||
| 98 |
|||
| Conway's Game of Life |
|||
| Task |
|||
|- |
|||
| 98 |
|||
| Guess the number/With feedback |
|||
| Task |
|||
|- |
|||
| 98 |
|||
| Horner's rule for polynomial evaluation |
|||
| Task |
|||
|- |
|||
| 97 |
|||
| Create a two-dimensional array at runtime |
|||
| Task |
|||
|- |
|||
| 97 |
|||
| Align columns |
|||
| Task |
|||
|- |
|||
| 97 |
|||
| Accumulator factory |
|||
| Task |
|||
|- |
|||
| 97 |
|||
| Perfect numbers |
|||
| Task |
|||
|- |
|||
| 96 |
|||
| Haversine formula |
|||
| Task |
|||
|- |
|||
| 96 |
|||
| Roman numerals/Decode |
|||
| Task |
|||
|- |
|||
| 96 |
|||
| Temperature conversion |
|||
| Task |
|||
|- |
|||
| 96 |
|||
| Assertions |
|||
| Task |
|||
|- |
|||
| 96 |
|||
| Identity matrix |
|||
| Task |
|||
|- |
|||
| 96 |
|||
| Strip a set of characters from a string |
|||
| Task |
|||
|- |
|||
| 95 |
|||
| String matching |
|||
| Task |
|||
|- |
|||
| 95 |
|||
| Averages/Pythagorean means |
|||
| Task |
|||
|- |
|||
| 95 |
|||
| Evaluate binomial coefficients |
|||
| Task |
|||
|- |
|||
| 94 |
|||
| Middle three digits |
|||
| Task |
|||
|- |
|||
| 94 |
|||
| Substring/Top and tail |
|||
| Task |
|||
|- |
|||
| 94 |
|||
| Variadic function |
|||
| Task |
|||
|- |
|||
| 93 |
|||
| Run-length encoding |
|||
| Task |
|||
|- |
|||
| 93 |
|||
| Zero to the zero power |
|||
| Task |
|||
|- |
|||
| 93 |
|||
| Catalan numbers |
|||
| Task |
|||
|- |
|||
| 92 |
|||
| Zig-zag matrix |
|||
| Task |
|||
|- |
|||
| 92 |
|||
| Strip whitespace from a string/Top and tail |
|||
| Task |
|||
|- |
|||
| 92 |
|||
| Arithmetic-geometric mean |
|||
| Task |
|||
|- |
|||
| 92 |
|||
| Program name |
|||
| Task |
|||
|- |
|||
| 92 |
|||
| Shell one-liner |
|||
| Task |
|||
|- |
|||
| 91 |
|||
| Trigonometric functions |
|||
| Task |
|||
|- |
|||
| 91 |
|||
| Exceptions |
|||
| Task |
|||
|- |
|||
| 90 |
|||
| Infinity |
|||
| Task |
|||
|- |
|||
| 90 |
|||
| String interpolation (included) |
|||
| Task |
|||
|- |
|||
| 90 |
|||
| Prime decomposition |
|||
| Task |
|||
|- |
|||
| 90 |
|||
| Letter frequency |
|||
| Task |
|||
|- |
|||
| 90 |
|||
| Regular expressions |
|||
| Task |
|||
|- |
|||
| 89 |
|||
| Combinations |
|||
| Task |
|||
|- |
|||
| 88 |
|||
| Sorting algorithms/Merge sort |
|||
| Task |
|||
|- |
|||
| 88 |
|||
| Random number generator (included) |
|||
| Task |
|||
|- |
|||
| 88 |
|||
|data-sort-value="0C24 game"| 24 game |
|||
| Task |
|||
|- |
|||
| 88 |
|||
| Sierpinski triangle |
|||
| Task |
|||
|- |
|||
| 88 |
|||
| Sorting algorithms/Selection sort |
|||
| Task |
|||
|- |
|||
| 88 |
|||
| Short-circuit evaluation |
|||
| Task |
|||
|- |
|||
| 88 |
|||
| Power set |
|||
| Task |
|||
|- |
|||
| 88 |
|||
| Enumerations |
|||
| Task |
|||
|- |
|||
| 87 |
|||
| One-dimensional cellular automata |
|||
| Task |
|||
|- |
|||
| 87 |
|||
| Collections |
|||
| Task |
|||
|- |
|||
| 87 |
|||
| Ordered words |
|||
| Task |
|||
|- |
|||
| 86 |
|||
| Anonymous recursion |
|||
| Task |
|||
|- |
|||
| 86 |
|||
| Interactive programming |
|||
| Task |
|||
|- |
|||
| 85 |
|||
| Levenshtein distance |
|||
| Task |
|||
|- |
|||
| 85 |
|||
| Comma quibbling |
|||
| Task |
|||
|- |
|||
| 85 |
|||
| Exponentiation operator |
|||
| Task |
|||
|- |
|||
| 85 |
|||
| Queue/Definition |
|||
| Task |
|||
|- |
|||
| 85 |
|||
| Sequence of non-squares |
|||
| Task |
|||
|- |
|||
| 84 |
|||
| Reverse words in a string |
|||
| Task |
|||
|- |
|||
| 84 |
|||
| Walk a directory/Non-recursively |
|||
| Task |
|||
|- |
|||
| 84 |
|||
| Range extraction |
|||
| Task |
|||
|- |
|||
| 84 |
|||
| First-class functions |
|||
| Task |
|||
|- |
|||
| 84 |
|||
| Arbitrary-precision integers (included) |
|||
| Task |
|||
|- |
|||
| 84 |
|||
| Look-and-say sequence |
|||
| Task |
|||
|- |
|||
| 84 |
|||
| Permutations |
|||
| Task |
|||
|- |
|||
| 83 |
|||
| Cumulative standard deviation |
|||
| Task |
|||
|- |
|||
| 83 |
|||
| Sort using a custom comparator |
|||
| Task |
|||
|- |
|||
| 82 |
|||
| Inheritance/Single |
|||
| Task |
|||
|- |
|||
| 82 |
|||
| Range expansion |
|||
| Task |
|||
|- |
|||
| 82 |
|||
| Nth root |
|||
| Task |
|||
|- |
|||
| 82 |
|||
| Bulls and cows |
|||
| Task |
|||
|- |
|||
| 81 |
|||
| Symmetric difference |
|||
| Task |
|||
|- |
|||
| 81 |
|||
|data-sort-value="md0B5"| MD5 |
|||
| Task |
|||
|- |
|||
| 81 |
|||
| Sorting algorithms/Gnome sort |
|||
| Task |
|||
|- |
|||
| 81 |
|||
|data-sort-value="sum multiples of 0B3 and 0B5"| Sum multiples of 3 and 5 |
|||
| Task |
|||
|- |
|||
| 81 |
|||
| Window creation |
|||
| Task |
|||
|- |
|||
| 81 |
|||
| String prepend |
|||
| Task |
|||
|- |
|||
| 81 |
|||
| Five weekends |
|||
| Task |
|||
|- |
|||
| 80 |
|||
| Evolutionary algorithm |
|||
| Task |
|||
|- |
|||
| 80 |
|||
| Y combinator |
|||
| Task |
|||
|- |
|||
| 80 |
|||
| Time a function |
|||
| Task |
|||
|- |
|||
| 80 |
|||
| Create an HTML table |
|||
| Task |
|||
|- |
|||
| 79 |
|||
| Sum digits of an integer |
|||
| Task |
|||
|- |
|||
| 79 |
|||
| String append |
|||
| Task |
|||
|- |
|||
| 79 |
|||
| Forward difference |
|||
| Task |
|||
|- |
|||
| 78 |
|||
| Averages/Simple moving average |
|||
| Task |
|||
|- |
|||
| 78 |
|||
| Call a function |
|||
| Task |
|||
|- |
|||
| 78 |
|||
| File modification time |
|||
| Task |
|||
|- |
|||
| 78 |
|||
| Price fraction |
|||
| Task |
|||
|- |
|||
| 78 |
|||
| Monty Hall problem |
|||
| Task |
|||
|- |
|||
| 77 |
|||
| Greatest subsequential sum |
|||
| Task |
|||
|- |
|||
| 77 |
|||
| Vector products |
|||
| Task |
|||
|- |
|||
| 77 |
|||
| Sierpinski carpet |
|||
| Task |
|||
|- |
|||
| 77 |
|||
| Abstract type |
|||
| Task |
|||
|- |
|||
| 77 |
|||
| Dragon curve |
|||
| Task |
|||
|- |
|||
| 76 |
|||
| Spiral matrix |
|||
| Task |
|||
|- |
|||
| 76 |
|||
| Menu |
|||
| Task |
|||
|- |
|||
| 76 |
|||
| Babbage problem |
|||
| Task |
|||
|- |
|||
| 76 |
|||
| Hamming numbers |
|||
| Task |
|||
|- |
|||
| 76 |
|||
| Langton's ant |
|||
| Task |
|||
|- |
|||
| 76 |
|||
| Sorting algorithms/Cocktail sort |
|||
| Task |
|||
|- |
|||
| 76 |
|||
| Entropy |
|||
| Task |
|||
|- |
|||
| 75 |
|||
| Map range |
|||
| Task |
|||
|- |
|||
| 75 |
|||
| Averages/Mode |
|||
| Task |
|||
|- |
|||
| 75 |
|||
| Walk a directory/Recursively |
|||
| Task |
|||
|- |
|||
| 75 |
|||
| Sorting algorithms/Bogosort |
|||
| Task |
|||
|- |
|||
| 75 |
|||
| Hello world/Line printer |
|||
| Task |
|||
|- |
|||
| 74 |
|||
| Simple windowed application |
|||
| Task |
|||
|- |
|||
| 74 |
|||
| Show the epoch |
|||
| Task |
|||
|- |
|||
| 74 |
|||
| Non-decimal radices/Convert |
|||
| Task |
|||
|- |
|||
| 74 |
|||
| The Twelve Days of Christmas |
|||
| Task |
|||
|- |
|||
| 74 |
|||
| Execute Brain**** |
|||
| Task |
|||
|- |
|||
| 74 |
|||
| JSON |
|||
| Task |
|||
|- |
|||
| 74 |
|||
| Web scraping |
|||
| Task |
|||
|- |
|||
| 74 |
|||
| Harshad or Niven series |
|||
| Task |
|||
|- |
|||
| 73 |
|||
| Monte Carlo methods |
|||
| Task |
|||
|- |
|||
| 73 |
|||
| Set |
|||
| Task |
|||
|- |
|||
| 73 |
|||
| Tree traversal |
|||
| Task |
|||
|- |
|||
| 73 |
|||
| Digital root |
|||
| Task |
|||
|- |
|||
| 73 |
|||
| Closures/Value capture |
|||
| Task |
|||
|- |
|||
| 73 |
|||
| Gray code |
|||
| Task |
|||
|- |
|||
| 72 |
|||
| Read a specific line from a file |
|||
| Task |
|||
|- |
|||
| 72 |
|||
| Queue/Usage |
|||
| Task |
|||
|- |
|||
| 72 |
|||
| SEDOLs |
|||
| Task |
|||
|- |
|||
| 72 |
|||
| Introspection |
|||
| Task |
|||
|- |
|||
| 72 |
|||
| Man or boy test |
|||
| Task |
|||
|- |
|||
| 71 |
|||
| Last Friday of each month |
|||
| Task |
|||
|- |
|||
| 71 |
|||
| Terminal control/Ringing the terminal bell |
|||
| Task |
|||
|- |
|||
| 71 |
|||
| Singly-linked list/Traversal |
|||
| Task |
|||
|- |
|||
| 71 |
|||
| CSV to HTML translation |
|||
| Task |
|||
|- |
|||
| 71 |
|||
| Number reversal game |
|||
| Task |
|||
|- |
|||
| 71 |
|||
| Sort an array of composite structures |
|||
| Task |
|||
|- |
|||
| 71 |
|||
| Literals/Floating point |
|||
| Task |
|||
|- |
|||
| 70 |
|||
| Count in factors |
|||
| Task |
|||
|- |
|||
| 70 |
|||
| CSV data manipulation |
|||
| Task |
|||
|- |
|||
| 70 |
|||
| Keyboard input/Obtain a Y or N response |
|||
| Task |
|||
|- |
|||
| 70 |
|||
| Bitmap |
|||
| Task |
|||
|- |
|||
| 70 |
|||
| URL decoding |
|||
| Task |
|||
|- |
|||
| 70 |
|||
| Sorting algorithms/Heapsort |
|||
| Task |
|||
|- |
|||
| 69 |
|||
| Linear congruential generator |
|||
| Task |
|||
|- |
|||
| 69 |
|||
| Sockets |
|||
| Task |
|||
|- |
|||
| 69 |
|||
| Amicable pairs |
|||
| Task |
|||
|- |
|||
| 69 |
|||
| Floyd's triangle |
|||
| Task |
|||
|- |
|||
| 68 |
|||
| Abundant, deficient and perfect number classifications |
|||
| Task |
|||
|- |
|||
| 68 |
|||
| String comparison |
|||
| Task |
|||
|- |
|||
| 68 |
|||
| Find the missing permutation |
|||
| Task |
|||
|- |
|||
| 68 |
|||
| List comprehensions |
|||
| Task |
|||
|- |
|||
| 68 |
|||
| Josephus problem |
|||
| Task |
|||
|- |
|||
| 68 |
|||
| XML/Input |
|||
| Task |
|||
|- |
|||
| 68 |
|||
| Take notes on the command line |
|||
| Task |
|||
|- |
|||
| 68 |
|||
| Top rank per group |
|||
| Task |
|||
|- |
|||
| 68 |
|||
|data-sort-value="knapsack problem/0B0-0B1"| Knapsack problem/0-1 |
|||
| Task |
|||
|- |
|||
| 68 |
|||
| Special characters |
|||
| Task |
|||
|- |
|||
| 67 |
|||
| Strip comments from a string |
|||
| Task |
|||
|- |
|||
| 67 |
|||
| Concurrent computing |
|||
| Task |
|||
|- |
|||
| 67 |
|||
| Kaprekar numbers |
|||
| Task |
|||
|- |
|||
| 67 |
|||
| Number names |
|||
| Task |
|||
|- |
|||
| 67 |
|||
| Address of a variable |
|||
| Task |
|||
|- |
|||
| 67 |
|||
| Date manipulation |
|||
| Task |
|||
|- |
|||
| 67 |
|||
| Catamorphism |
|||
| Task |
|||
|- |
|||
| 67 |
|||
| Roots of unity |
|||
| Task |
|||
|- |
|||
| 67 |
|||
| Sorting algorithms/Shell sort |
|||
| Task |
|||
|- |
|||
| 67 |
|||
| Terminal control/Clear the screen |
|||
| Task |
|||
|- |
|||
| 67 |
|||
| Find common directory path |
|||
| Task |
|||
|- |
|||
| 66 |
|||
| Unicode variable names |
|||
| Task |
|||
|- |
|||
| 66 |
|||
| URL encoding |
|||
| Task |
|||
|- |
|||
| 66 |
|||
| Singly-linked list/Element definition |
|||
| Task |
|||
|- |
|||
| 66 |
|||
| Stair-climbing puzzle |
|||
| Task |
|||
|- |
|||
| 66 |
|||
| Non-decimal radices/Output |
|||
| Task |
|||
|- |
|||
| 66 |
|||
| Playing cards |
|||
| Task |
|||
|- |
|||
| 66 |
|||
| Box the compass |
|||
| Task |
|||
|- |
|||
| 66 |
|||
| Soundex |
|||
| Task |
|||
|- |
|||
| 66 |
|||
| Dynamic variable names |
|||
| Task |
|||
|- |
|||
| 65 |
|||
| Polymorphism |
|||
| Task |
|||
|- |
|||
| 65 |
|||
| Equilibrium index |
|||
| Task |
|||
|- |
|||
| 65 |
|||
| Order two numerical lists |
|||
| Task |
|||
|- |
|||
| 65 |
|||
| Longest common subsequence |
|||
| Task |
|||
|- |
|||
| 65 |
|||
| Lucas-Lehmer test |
|||
| Task |
|||
|- |
|||
| 65 |
|||
| Bitmap/Bresenham's line algorithm |
|||
| Task |
|||
|- |
|||
| 64 |
|||
| Sorting algorithms/Counting sort |
|||
| Task |
|||
|- |
|||
| 64 |
|||
| Empty directory |
|||
| Task |
|||
|- |
|||
| 64 |
|||
| Find the last Sunday of each month |
|||
| Task |
|||
|- |
|||
| 64 |
|||
| Write float arrays to a text file |
|||
| Task |
|||
|- |
|||
| 64 |
|||
| Flow-control structures |
|||
| Task |
|||
|- |
|||
| 63 |
|||
| Sorting algorithms/Comb sort |
|||
| Task |
|||
|- |
|||
| 63 |
|||
| Anagrams/Deranged anagrams |
|||
| Task |
|||
|- |
|||
| 63 |
|||
| Parsing/RPN calculator algorithm |
|||
| Task |
|||
|- |
|||
| 63 |
|||
| Multifactorial |
|||
| Task |
|||
|- |
|||
| 63 |
|||
| Hello world/Web server |
|||
| Task |
|||
|- |
|||
| 63 |
|||
| Multiple distinct objects |
|||
| Task |
|||
|- |
|||
| 63 |
|||
| Semordnilap |
|||
| Task |
|||
|- |
|||
| 63 |
|||
| Here document |
|||
| Task |
|||
|- |
|||
| 63 |
|||
| Word wrap |
|||
| Task |
|||
|- |
|||
| 63 |
|||
| N'th |
|||
| Task |
|||
|- |
|||
| 63 |
|||
| Forest fire |
|||
| Task |
|||
|- |
|||
| 63 |
|||
| Read a configuration file |
|||
| Task |
|||
|- |
|||
| 63 |
|||
| Averages/Mean angle |
|||
| Task |
|||
|- |
|||
| 62 |
|||
| Largest int from concatenated ints |
|||
| Task |
|||
|- |
|||
| 62 |
|||
| Sorting algorithms/Stooge sort |
|||
| Task |
|||
|- |
|||
| 62 |
|||
| Guess the number/With feedback (player) |
|||
| Task |
|||
|- |
|||
| 62 |
|||
| Compare a list of strings |
|||
| Task |
|||
|- |
|||
| 62 |
|||
| Euler method |
|||
| Task |
|||
|- |
|||
| 62 |
|||
| Enforced immutability |
|||
| Task |
|||
|- |
|||
| 62 |
|||
| Fibonacci n-step number sequences |
|||
| Task |
|||
|- |
|||
| 62 |
|||
| Jensen's Device |
|||
| Task |
|||
|- |
|||
| 62 |
|||
| Hofstadter Q sequence |
|||
| Task |
|||
|- |
|||
| 62 |
|||
| Pythagorean triples |
|||
| Task |
|||
|- |
|||
| 62 |
|||
| Exceptions/Catch an exception thrown in a nested call |
|||
| Task |
|||
|- |
|||
| 62 |
|||
| Vigenère cipher |
|||
| Task |
|||
|- |
|||
| 62 |
|||
| Count the coins |
|||
| Task |
|||
|- |
|||
| 62 |
|||
| Convert seconds to compound duration |
|||
| Task |
|||
|- |
|||
| 62 |
|||
| Constrained random points on a circle |
|||
| Task |
|||
|- |
|||
| 61 |
|||
| Sudoku |
|||
| Task |
|||
|- |
|||
| 61 |
|||
| Trabb Pardo–Knuth algorithm |
|||
| Task |
|||
|- |
|||
| 61 |
|||
| Call an object method |
|||
| Task |
|||
|- |
|||
| 61 |
|||
| Sort disjoint sublist |
|||
| Task |
|||
|- |
|||
| 61 |
|||
| Long multiplication |
|||
| Task |
|||
|- |
|||
| 61 |
|||
| Hello world/Newbie |
|||
| Task |
|||
|- |
|||
| 61 |
|||
| Draw a sphere |
|||
| Task |
|||
|- |
|||
| 61 |
|||
| Animation |
|||
| Task |
|||
|- |
|||
| 60 |
|||
| Sort stability |
|||
| Task |
|||
|- |
|||
| 60 |
|||
|data-sort-value="execute hq0B9+"| Execute HQ9+ |
|||
| Task |
|||
|- |
|||
| 60 |
|||
| Operator precedence |
|||
| Task |
|||
|- |
|||
| 60 |
|||
| Numerical integration |
|||
| Task |
|||
|- |
|||
| 60 |
|||
| Probabilistic choice |
|||
| Task |
|||
|- |
|||
| 60 |
|||
| Strip control codes and extended characters from a string |
|||
| Task |
|||
|- |
|||
| 60 |
|||
| Singly-linked list/Element insertion |
|||
| Task |
|||
|- |
|||
| 59 |
|||
| Four bit adder |
|||
| Task |
|||
|- |
|||
| 59 |
|||
| Named parameters |
|||
| Task |
|||
|- |
|||
| 59 |
|||
| Runtime evaluation |
|||
| Task |
|||
|- |
|||
| 59 |
|||
| Gamma function |
|||
| Task |
|||
|- |
|||
| 59 |
|||
|data-sort-value="write language name in 0B3d ascii"| Write language name in 3D ASCII |
|||
| Task |
|||
|- |
|||
| 59 |
|||
| Fork |
|||
| Task |
|||
|- |
|||
| 59 |
|||
| Undefined values |
|||
| Task |
|||
|- |
|||
| 58 |
|||
| Benford's law |
|||
| Task |
|||
|- |
|||
| 58 |
|||
| Roots of a quadratic function |
|||
| Task |
|||
|- |
|||
| 58 |
|||
| Text processing/Max licenses in use |
|||
| Task |
|||
|- |
|||
| 58 |
|||
| One of n lines in a file |
|||
| Task |
|||
|- |
|||
| 58 |
|||
| Variable size/Get |
|||
| Task |
|||
|- |
|||
| 58 |
|||
| Remove lines from a file |
|||
| Task |
|||
|- |
|||
| 58 |
|||
| Call a foreign-language function |
|||
| Task |
|||
|- |
|||
| 57 |
|||
| Fractal tree |
|||
| Task |
|||
|- |
|||
| 57 |
|||
| Optional parameters |
|||
| Task |
|||
|- |
|||
| 57 |
|||
| Priority queue |
|||
| Task |
|||
|- |
|||
| 57 |
|||
| Phrase reversals |
|||
| Task |
|||
|- |
|||
| 57 |
|||
| Roots of a function |
|||
| Task |
|||
|- |
|||
| 57 |
|||
| IBAN |
|||
| Task |
|||
|- |
|||
| 57 |
|||
| Quaternion type |
|||
| Task |
|||
|- |
|||
| 57 |
|||
| Pi |
|||
| Task |
|||
|- |
|||
| 57 |
|||
| Runge-Kutta method |
|||
| Task |
|||
|- |
|||
| 57 |
|||
| Proper divisors |
|||
| Draft |
|||
|- |
|||
| 57 |
|||
| Arithmetic/Rational |
|||
| Task |
|||
|- |
|||
| 57 |
|||
| Closest-pair problem |
|||
| Task |
|||
|- |
|||
| 57 |
|||
| Rock-paper-scissors |
|||
| Task |
|||
|- |
|||
| 57 |
|||
| Combinations with repetitions |
|||
| Task |
|||
|- |
|||
| 56 |
|||
| Memory allocation |
|||
| Task |
|||
|- |
|||
| 56 |
|||
| Catalan numbers/Pascal's triangle |
|||
| Task |
|||
|- |
|||
| 56 |
|||
| Magic squares of odd order |
|||
| Task |
|||
|- |
|||
| 56 |
|||
| Almost prime |
|||
| Task |
|||
|- |
|||
| 56 |
|||
| Horizontal sundial calculations |
|||
| Task |
|||
|- |
|||
| 56 |
|||
| Host introspection |
|||
| Task |
|||
|- |
|||
| 56 |
|||
| HTTPS |
|||
| Task |
|||
|- |
|||
| 56 |
|||
|data-sort-value="hofstadter-conway $0C10,0D000 sequence"| Hofstadter-Conway $10,000 sequence |
|||
| Task |
|||
|- |
|||
| 56 |
|||
|data-sort-value="sha-0B1"| SHA-1 |
|||
| Task |
|||
|- |
|||
| 56 |
|||
| Zeckendorf number representation |
|||
| Task |
|||
|- |
|||
| 56 |
|||
| Self-describing numbers |
|||
| Task |
|||
|- |
|||
| 56 |
|||
| Van der Corput sequence |
|||
| Task |
|||
|- |
|||
| 55 |
|||
| Special variables |
|||
| Task |
|||
|- |
|||
| 55 |
|||
| Knapsack problem/Unbounded |
|||
| Task |
|||
|- |
|||
| 55 |
|||
| AKS test for primes |
|||
| Task |
|||
|- |
|||
| 55 |
|||
| Narcissistic decimal number |
|||
| Task |
|||
|- |
|||
| 55 |
|||
| Modular inverse |
|||
| Task |
|||
|- |
|||
| 55 |
|||
| Sorting algorithms/Sleep sort |
|||
| Task |
|||
|- |
|||
| 55 |
|||
| Cholesky decomposition |
|||
| Task |
|||
|- |
|||
| 55 |
|||
| Extend your language |
|||
| Task |
|||
|- |
|||
| 55 |
|||
| XML/Output |
|||
| Task |
|||
|- |
|||
| 55 |
|||
|data-sort-value="crc-0C32"| CRC-32 |
|||
| Task |
|||
|- |
|||
| 55 |
|||
| Sorting algorithms/Pancake sort |
|||
| Task |
|||
|- |
|||
| 55 |
|||
| Currying |
|||
| Task |
|||
|- |
|||
| 55 |
|||
| Fast Fourier transform |
|||
| Task |
|||
|- |
|||
| 54 |
|||
| Documentation |
|||
| Task |
|||
|- |
|||
| 54 |
|||
|data-sort-value="0C24 game/solve"| 24 game/Solve |
|||
| Task |
|||
|- |
|||
| 54 |
|||
| Partial function application |
|||
| Task |
|||
|- |
|||
| 54 |
|||
| Jump anywhere |
|||
| Task |
|||
|- |
|||
| 54 |
|||
| Maze generation |
|||
| Task |
|||
|- |
|||
| 54 |
|||
|data-sort-value="sha-0D256"| SHA-256 |
|||
| Task |
|||
|- |
|||
| 54 |
|||
| Non-decimal radices/Input |
|||
| Task |
|||
|- |
|||
| 53 |
|||
| Stem-and-leaf plot |
|||
| Task |
|||
|- |
|||
| 53 |
|||
| Binary strings |
|||
| Task |
|||
|- |
|||
| 53 |
|||
| Globally replace text in several files |
|||
| Task |
|||
|- |
|||
| 53 |
|||
| Test a function |
|||
| Task |
|||
|- |
|||
| 53 |
|||
| Calendar |
|||
| Task |
|||
|- |
|||
| 53 |
|||
| Reduced row echelon form |
|||
| Task |
|||
|- |
|||
| 53 |
|||
| Huffman coding |
|||
| Task |
|||
|- |
|||
| 53 |
|||
| Animate a pendulum |
|||
| Task |
|||
|- |
|||
| 53 |
|||
| Yin and yang |
|||
| Task |
|||
|- |
|||
| 53 |
|||
| Factors of a Mersenne number |
|||
| Task |
|||
|- |
|||
| 53 |
|||
| Old lady swallowed a fly |
|||
| Task |
|||
|- |
|||
| 53 |
|||
| Pernicious numbers |
|||
| Task |
|||
|- |
|||
| 53 |
|||
| Inheritance/Multiple |
|||
| Task |
|||
|- |
|||
| 52 |
|||
| Fibonacci word |
|||
| Task |
|||
|- |
|||
| 52 |
|||
| Best shuffle |
|||
| Task |
|||
|- |
|||
| 52 |
|||
| Extreme floating point values |
|||
| Task |
|||
|- |
|||
| 52 |
|||
| Sorting algorithms/Bead sort |
|||
| Task |
|||
|- |
|||
| 52 |
|||
| Odd word problem |
|||
| Task |
|||
|- |
|||
| 52 |
|||
| Synchronous concurrency |
|||
| Task |
|||
|- |
|||
| 52 |
|||
| XML/XPath |
|||
| Task |
|||
|- |
|||
| 52 |
|||
| Scope modifiers |
|||
| Task |
|||
|- |
|||
| 52 |
|||
| Write entire file |
|||
| Task |
|||
|- |
|||
| 51 |
|||
| Knapsack problem/Continuous |
|||
| Task |
|||
|- |
|||
| 51 |
|||
| Rep-string |
|||
| Task |
|||
|- |
|||
| 51 |
|||
| Sequence of primes by trial division |
|||
| Task |
|||
|- |
|||
| 51 |
|||
| Repeat |
|||
| Draft |
|||
|- |
|||
| 51 |
|||
| Dinesman's multiple-dwelling problem |
|||
| Task |
|||
|- |
|||
| 51 |
|||
| Hash join |
|||
| Task |
|||
|- |
|||
| 51 |
|||
| Arithmetic evaluation |
|||
| Task |
|||
|- |
|||
| 51 |
|||
| Rosetta Code/Count examples |
|||
| Task |
|||
|- |
|||
| 51 |
|||
| Singleton |
|||
| Task |
|||
|- |
|||
| 50 |
|||
| Miller–Rabin primality test |
|||
| Task |
|||
|- |
|||
| 50 |
|||
| Unbias a random generator |
|||
| Task |
|||
|- |
|||
| 50 |
|||
| Compile-time calculation |
|||
| Task |
|||
|- |
|||
| 50 |
|||
| Brownian tree |
|||
| Task |
|||
|- |
|||
| 50 |
|||
| Unix/ls |
|||
| Task |
|||
|- |
|||
| 50 |
|||
| Truncate a file |
|||
| Task |
|||
|- |
|||
| 50 |
|||
| Stack traces |
|||
| Task |
|||
|- |
|||
| 50 |
|||
| Continued fraction |
|||
| Task |
|||
|- |
|||
| 50 |
|||
| Draw a clock |
|||
| Task |
|||
|- |
|||
| 50 |
|||
| Runtime evaluation/In an environment |
|||
| Task |
|||
|- |
|||
| 50 |
|||
| Add a variable to a class instance at runtime |
|||
| Task |
|||
|- |
|||
| 50 |
|||
| Sorting algorithms/Permutation sort |
|||
| Task |
|||
|- |
|||
| 50 |
|||
| Semiprime |
|||
| Task |
|||
|- |
|||
| 49 |
|||
| Knight's tour |
|||
| Task |
|||
|- |
|||
| 49 |
|||
| Averages/Mean time of day |
|||
| Task |
|||
|- |
|||
| 49 |
|||
| Plot coordinate pairs |
|||
| Task |
|||
|- |
|||
| 49 |
|||
| Deal cards for FreeCell |
|||
| Task |
|||
|- |
|||
| 49 |
|||
| Tic-tac-toe |
|||
| Task |
|||
|- |
|||
| 49 |
|||
| Euler's sum of powers conjecture |
|||
| Task |
|||
|- |
|||
| 49 |
|||
| LZW compression |
|||
| Task |
|||
|- |
|||
| 49 |
|||
| Morse code |
|||
| Task |
|||
|- |
|||
| 49 |
|||
| Topological sort |
|||
| Task |
|||
|- |
|||
| 48 |
|||
| Pointers and references |
|||
| Task |
|||
|- |
|||
| 48 |
|||
| Generator/Exponential |
|||
| Task |
|||
|- |
|||
| 48 |
|||
| Circles of given radius through two points |
|||
| Task |
|||
|- |
|||
| 48 |
|||
| I before E except after C |
|||
| Task |
|||
|- |
|||
| 48 |
|||
| Modular exponentiation |
|||
| Task |
|||
|- |
|||
| 48 |
|||
| Modulinos |
|||
| Draft |
|||
|- |
|||
| 48 |
|||
| Unicode strings |
|||
| Task |
|||
|- |
|||
| 48 |
|||
| Terminal control/Display an extended character |
|||
| Task |
|||
|- |
|||
| 47 |
|||
| Bitmap/Write a PPM file |
|||
| Task |
|||
|- |
|||
| 47 |
|||
| Send email |
|||
| Task |
|||
|- |
|||
| 47 |
|||
| Left factorials |
|||
| Task |
|||
|- |
|||
| 47 |
|||
| Split a character string based on change of character |
|||
| Task |
|||
|- |
|||
| 47 |
|||
| Non-continuous subsequences |
|||
| Task |
|||
|- |
|||
| 47 |
|||
| Wireworld |
|||
| Task |
|||
|- |
|||
| 47 |
|||
| Dutch national flag problem |
|||
| Task |
|||
|- |
|||
| 47 |
|||
| Integer overflow |
|||
| Task |
|||
|- |
|||
| 47 |
|||
| Multisplit |
|||
| Task |
|||
|- |
|||
| 47 |
|||
| Statistics/Basic |
|||
| Task |
|||
|- |
|||
| 47 |
|||
| Doubly-linked list/Element definition |
|||
| Task |
|||
|- |
|||
| 47 |
|||
| Mouse position |
|||
| Task |
|||
|- |
|||
| 47 |
|||
| Rosetta Code/Rank languages by popularity |
|||
| Task |
|||
|- |
|||
| 46 |
|||
| Grayscale image |
|||
| Task |
|||
|- |
|||
| 46 |
|||
| Truncatable primes |
|||
| Task |
|||
|- |
|||
| 46 |
|||
|data-sort-value="text processing/0B2"| Text processing/2 |
|||
| Task |
|||
|- |
|||
| 46 |
|||
| Nested function |
|||
| Task |
|||
|- |
|||
| 46 |
|||
| User input/Graphical |
|||
| Task |
|||
|- |
|||
| 46 |
|||
|data-sort-value="text processing/0B1"| Text processing/1 |
|||
| Task |
|||
|- |
|||
| 45 |
|||
| XML/DOM serialization |
|||
| Task |
|||
|- |
|||
| 45 |
|||
| JortSort |
|||
| Task |
|||
|- |
|||
| 45 |
|||
| Define a primitive data type |
|||
| Task |
|||
|- |
|||
| 45 |
|||
| Draw a cuboid |
|||
| Task |
|||
|- |
|||
| 45 |
|||
| Random number generator (device) |
|||
| Task |
|||
|- |
|||
| 45 |
|||
| Thue-Morse |
|||
| Task |
|||
|- |
|||
| 45 |
|||
| Maximum triangle path sum |
|||
| Task |
|||
|- |
|||
| 45 |
|||
| Respond to an unknown method call |
|||
| Task |
|||
|- |
|||
| 45 |
|||
| Ludic numbers |
|||
| Task |
|||
|- |
|||
| 45 |
|||
| First-class functions/Use numbers analogously |
|||
| Task |
|||
|- |
|||
| 45 |
|||
| Stable marriage problem |
|||
| Task |
|||
|- |
|||
| 45 |
|||
| Seven-sided dice from five-sided dice |
|||
| Task |
|||
|- |
|||
| 45 |
|||
| Handle a signal |
|||
| Task |
|||
|- |
|||
| 45 |
|||
| Munchausen numbers |
|||
| Task |
|||
|- |
|||
| 44 |
|||
| Chinese remainder theorem |
|||
| Task |
|||
|- |
|||
| 44 |
|||
| Table creation/Postal addresses |
|||
| Task |
|||
|- |
|||
| 44 |
|||
| Delegates |
|||
| Task |
|||
|- |
|||
| 44 |
|||
| Sierpinski triangle/Graphical |
|||
| Task |
|||
|- |
|||
| 44 |
|||
| Heronian triangles |
|||
| Task |
|||
|- |
|||
| 44 |
|||
| Population count |
|||
| Task |
|||
|- |
|||
| 44 |
|||
| Matrix-exponentiation operator |
|||
| Task |
|||
|- |
|||
| 44 |
|||
| Ternary logic |
|||
| Task |
|||
|- |
|||
| 44 |
|||
| General FizzBuzz |
|||
| Task |
|||
|- |
|||
| 43 |
|||
| Discordian date |
|||
| Task |
|||
|- |
|||
| 43 |
|||
| Longest increasing subsequence |
|||
| Task |
|||
|- |
|||
| 43 |
|||
| Call a function in a shared library |
|||
| Task |
|||
|- |
|||
| 43 |
|||
| Bernoulli numbers |
|||
| Task |
|||
|- |
|||
| 43 |
|||
| Keyboard input/Keypress check |
|||
| Task |
|||
|- |
|||
| 43 |
|||
| Munching squares |
|||
| Task |
|||
|- |
|||
| 43 |
|||
| Quickselect algorithm |
|||
| Task |
|||
|- |
|||
| 43 |
|||
| Terminal control/Cursor positioning |
|||
| Task |
|||
|- |
|||
| 42 |
|||
| Mad Libs |
|||
| Task |
|||
|- |
|||
| 42 |
|||
| Emirp primes |
|||
| Task |
|||
|- |
|||
| 42 |
|||
| Send an unknown method call |
|||
| Task |
|||
|- |
|||
| 42 |
|||
|data-sort-value="0B9 billion names of god the integer"| 9 billion names of God the integer |
|||
| Task |
|||
|- |
|||
| 42 |
|||
| Polymorphic copy |
|||
| Task |
|||
|- |
|||
| 42 |
|||
|data-sort-value="0C15 puzzle game"| 15 Puzzle Game |
|||
| Task |
|||
|- |
|||
| 41 |
|||
| Doubly-linked list/Element insertion |
|||
| Task |
|||
|- |
|||
| 41 |
|||
| Colour bars/Display |
|||
| Task |
|||
|- |
|||
| 41 |
|||
| Strip block comments |
|||
| Task |
|||
|- |
|||
| 41 |
|||
| Inverted syntax |
|||
| Task |
|||
|- |
|||
| 41 |
|||
| Longest string challenge |
|||
| Task |
|||
|- |
|||
| 41 |
|||
| Two Sum |
|||
| Draft |
|||
|- |
|||
| 41 |
|||
| Convert decimal number to rational |
|||
| Task |
|||
|- |
|||
| 41 |
|||
| Holidays related to Easter |
|||
| Task |
|||
|- |
|||
| 41 |
|||
| Color of a screen pixel |
|||
| Task |
|||
|- |
|||
| 41 |
|||
| Rate counter |
|||
| Task |
|||
|- |
|||
| 41 |
|||
| Universal Turing machine |
|||
| Task |
|||
|- |
|||
| 41 |
|||
| Dining philosophers |
|||
| Task |
|||
|- |
|||
| 41 |
|||
| Make directory path |
|||
| Task |
|||
|- |
|||
| 41 |
|||
| Exponentiation order |
|||
| Task |
|||
|- |
|||
| 41 |
|||
| Iterated digits squaring |
|||
| Task |
|||
|- |
|||
| 41 |
|||
| Execute a Markov algorithm |
|||
| Task |
|||
|- |
|||
| 41 |
|||
| Hofstadter Figure-Figure sequences |
|||
| Task |
|||
|- |
|||
| 40 |
|||
| Echo server |
|||
| Task |
|||
|- |
|||
| 40 |
|||
| Last letter-first letter |
|||
| Task |
|||
|- |
|||
| 40 |
|||
| Doubly-linked list/Traversal |
|||
| Task |
|||
|- |
|||
| 40 |
|||
| Parsing/Shunting-yard algorithm |
|||
| Task |
|||
|- |
|||
| 40 |
|||
| Verify distribution uniformity/Naive |
|||
| Task |
|||
|- |
|||
| 40 |
|||
| Move-to-front algorithm |
|||
| Task |
|||
|- |
|||
| 39 |
|||
| GUI component interaction |
|||
| Task |
|||
|- |
|||
| 39 |
|||
| Get system command output |
|||
| Task |
|||
|- |
|||
| 39 |
|||
| Zebra puzzle |
|||
| Task |
|||
|- |
|||
| 39 |
|||
| Search a list of records |
|||
| Task |
|||
|- |
|||
| 39 |
|||
| Archimedean spiral |
|||
| Task |
|||
|- |
|||
| 39 |
|||
| Polynomial regression |
|||
| Task |
|||
|- |
|||
| 39 |
|||
| Bitmap/Read a PPM file |
|||
| Task |
|||
|- |
|||
| 39 |
|||
| Extract file extension |
|||
| Draft |
|||
|- |
|||
| 39 |
|||
| Barnsley fern |
|||
| Task |
|||
|- |
|||
| 39 |
|||
| Greyscale bars/Display |
|||
| Task |
|||
|- |
|||
| 39 |
|||
| Bitmap/Flood fill |
|||
| Task |
|||
|- |
|||
| 38 |
|||
| Polynomial long division |
|||
| Task |
|||
|- |
|||
| 38 |
|||
| History variables |
|||
| Task |
|||
|- |
|||
| 38 |
|||
| Digital root/Multiplicative digital root |
|||
| Task |
|||
|- |
|||
| 38 |
|||
| FASTA format |
|||
| Task |
|||
|- |
|||
| 38 |
|||
| Set consolidation |
|||
| Task |
|||
|- |
|||
| 38 |
|||
| Determine if only one instance is running |
|||
| Task |
|||
|- |
|||
| 38 |
|||
| Sorting algorithms/Strand sort |
|||
| Task |
|||
|- |
|||
| 38 |
|||
| Problem of Apollonius |
|||
| Task |
|||
|- |
|||
| 38 |
|||
| Secure temporary file |
|||
| Task |
|||
|- |
|||
| 38 |
|||
| Sparkline in unicode |
|||
| Task |
|||
|- |
|||
| 38 |
|||
| DNS query |
|||
| Task |
|||
|- |
|||
| 38 |
|||
| Atomic updates |
|||
| Task |
|||
|- |
|||
| 38 |
|||
| OpenGL |
|||
| Task |
|||
|- |
|||
| 37 |
|||
| Fractran |
|||
| Task |
|||
|- |
|||
| 37 |
|||
| Variable size/Set |
|||
| Task |
|||
|- |
|||
| 37 |
|||
| Pig the dice game |
|||
| Task |
|||
|- |
|||
| 37 |
|||
| Parametric polymorphism |
|||
| Task |
|||
|- |
|||
| 37 |
|||
| Terminal control/Inverse video |
|||
| Task |
|||
|- |
|||
| 37 |
|||
| Image noise |
|||
| Task |
|||
|- |
|||
| 37 |
|||
| Perfect shuffle |
|||
| Task |
|||
|- |
|||
| 37 |
|||
| Subtractive generator |
|||
| Task |
|||
|- |
|||
| 36 |
|||
| Dijkstra's algorithm |
|||
| Draft |
|||
|- |
|||
| 36 |
|||
| Metaprogramming |
|||
| Task |
|||
|- |
|||
| 36 |
|||
|data-sort-value="generate chess0D960 starting position"| Generate Chess960 starting position |
|||
| Task |
|||
|- |
|||
| 36 |
|||
| Pascal matrix generation |
|||
| Task |
|||
|- |
|||
| 36 |
|||
| Narcissist |
|||
| Task |
|||
|- |
|||
| 36 |
|||
| Doubly-linked list/Definition |
|||
| Task |
|||
|- |
|||
| 36 |
|||
| Terminal control/Coloured text |
|||
| Task |
|||
|- |
|||
| 36 |
|||
| Active object |
|||
| Task |
|||
|- |
|||
| 36 |
|||
| Inverted index |
|||
| Task |
|||
|- |
|||
| 36 |
|||
| Department Numbers |
|||
| Task |
|||
|- |
|||
| 36 |
|||
|data-sort-value="md0B5/implementation"| MD5/Implementation |
|||
| Task |
|||
|- |
|||
| 36 |
|||
| Permutations by swapping |
|||
| Task |
|||
|- |
|||
| 36 |
|||
| Stern-Brocot sequence |
|||
| Task |
|||
|- |
|||
| 36 |
|||
| Terminal control/Dimensions |
|||
| Task |
|||
|- |
|||
| 36 |
|||
| Twelve statements |
|||
| Task |
|||
|- |
|||
| 35 |
|||
| Validate International Securities Identification Number |
|||
| Task |
|||
|- |
|||
| 35 |
|||
| Percentage difference between images |
|||
| Task |
|||
|- |
|||
| 35 |
|||
| Append a record to the end of a text file |
|||
| Task |
|||
|- |
|||
| 35 |
|||
| Ray-casting algorithm |
|||
| Task |
|||
|- |
|||
| 35 |
|||
| Knapsack problem/Bounded |
|||
| Task |
|||
|- |
|||
| 35 |
|||
| Subleq |
|||
| Task |
|||
|- |
|||
| 35 |
|||
| Farey sequence |
|||
| Task |
|||
|- |
|||
| 35 |
|||
| Kronecker product |
|||
| Task |
|||
|- |
|||
| 35 |
|||
|data-sort-value="sum to 0D100"| Sum to 100 |
|||
| Task |
|||
|- |
|||
| 35 |
|||
|data-sort-value="base0C64 encode data"| Base64 encode data |
|||
| Draft |
|||
|- |
|||
| 35 |
|||
| Bulls and cows/Player |
|||
| Task |
|||
|- |
|||
| 35 |
|||
| Matrix arithmetic |
|||
| Task |
|||
|- |
|||
| 35 |
|||
| Visualize a tree |
|||
| Task |
|||
|- |
|||
| 35 |
|||
| Permutations/Derangements |
|||
| Task |
|||
|- |
|||
| 35 |
|||
| Leonardo numbers |
|||
| Task |
|||
|- |
|||
| 35 |
|||
| Bitmap/Midpoint circle algorithm |
|||
| Task |
|||
|- |
|||
| 35 |
|||
| Variable-length quantity |
|||
| Task |
|||
|- |
|||
| 35 |
|||
| Smith numbers |
|||
| Task |
|||
|- |
|||
| 34 |
|||
| Average loop length |
|||
| Task |
|||
|- |
|||
| 34 |
|||
| Longest common prefix |
|||
| Draft |
|||
|- |
|||
| 34 |
|||
| Element-wise operations |
|||
| Task |
|||
|- |
|||
| 34 |
|||
| Self-referential sequence |
|||
| Task |
|||
|- |
|||
| 34 |
|||
| Calendar - for "REAL" programmers |
|||
| Task |
|||
|- |
|||
| 34 |
|||
| Tokenize a string with escaping |
|||
| Task |
|||
|- |
|||
| 34 |
|||
| Jaro distance |
|||
| Task |
|||
|- |
|||
| 34 |
|||
| Keyboard input/Flush the keyboard buffer |
|||
| Task |
|||
|- |
|||
| 34 |
|||
| Statistics/Normal distribution |
|||
| Task |
|||
|- |
|||
| 34 |
|||
| Parallel calculations |
|||
| Task |
|||
|- |
|||
| 34 |
|||
| Balanced ternary |
|||
| Task |
|||
|- |
|||
| 34 |
|||
| GUI enabling/disabling of controls |
|||
| Task |
|||
|- |
|||
| 34 |
|||
| Hickerson series of almost integers |
|||
| Task |
|||
|- |
|||
| 34 |
|||
| Chaos game |
|||
| Task |
|||
|- |
|||
| 33 |
|||
| Parsing/RPN to infix conversion |
|||
| Task |
|||
|- |
|||
| 33 |
|||
| Start from a main routine |
|||
| Task |
|||
|- |
|||
| 33 |
|||
| Gaussian elimination |
|||
| Task |
|||
|- |
|||
| 33 |
|||
| Password generator |
|||
| Task |
|||
|- |
|||
| 33 |
|||
| Amb |
|||
| Task |
|||
|- |
|||
| 33 |
|||
| Sorting algorithms/Radix sort |
|||
| Task |
|||
|- |
|||
| 33 |
|||
| Naming conventions |
|||
| Task |
|||
|- |
|||
| 33 |
|||
| Ulam spiral (for primes) |
|||
| Task |
|||
|- |
|||
| 33 |
|||
| Topswops |
|||
| Task |
|||
|- |
|||
| 33 |
|||
|data-sort-value="carmichael 0B3 strong pseudoprimes"| Carmichael 3 strong pseudoprimes |
|||
| Task |
|||
|- |
|||
| 33 |
|||
| Combinations and permutations |
|||
| Task |
|||
|- |
|||
| 33 |
|||
| Constrained genericity |
|||
| Task |
|||
|- |
|||
| 32 |
|||
| Pascal's triangle/Puzzle |
|||
| Task |
|||
|- |
|||
| 32 |
|||
| Multiline shebang |
|||
| Draft |
|||
|- |
|||
| 32 |
|||
| S-Expressions |
|||
| Task |
|||
|- |
|||
| 32 |
|||
| Sort three variables |
|||
| Task |
|||
|- |
|||
| 32 |
|||
|data-sort-value="0E2048"| 2048 |
|||
| Task |
|||
|- |
|||
| 32 |
|||
| Vampire number |
|||
| Task |
|||
|- |
|||
| 32 |
|||
| Knuth's algorithm S |
|||
| Task |
|||
|- |
|||
| 32 |
|||
| Aliquot sequence classifications |
|||
| Task |
|||
|- |
|||
| 32 |
|||
| Order disjoint list items |
|||
| Task |
|||
|- |
|||
| 32 |
|||
| Test integerness |
|||
| Task |
|||
|- |
|||
| 32 |
|||
|data-sort-value="0B4-rings or 0B4-squares puzzle"| 4-rings or 4-squares puzzle |
|||
| Task |
|||
|- |
|||
| 31 |
|||
| Events |
|||
| Task |
|||
|- |
|||
| 31 |
|||
| Extensible prime generator |
|||
| Task |
|||
|- |
|||
| 31 |
|||
| Metered concurrency |
|||
| Task |
|||
|- |
|||
| 31 |
|||
| Deepcopy |
|||
| Task |
|||
|- |
|||
| 31 |
|||
| CUSIP |
|||
| Task |
|||
|- |
|||
| 31 |
|||
| Break OO privacy |
|||
| Task |
|||
|- |
|||
| 31 |
|||
| Vector |
|||
| Draft |
|||
|- |
|||
| 31 |
|||
| Taxicab numbers |
|||
| Task |
|||
|- |
|||
| 31 |
|||
|data-sort-value="md0B4"| MD4 |
|||
| Task |
|||
|- |
|||
| 31 |
|||
| Permutation test |
|||
| Task |
|||
|- |
|||
| 31 |
|||
| Voronoi diagram |
|||
| Task |
|||
|- |
|||
| 30 |
|||
| Function prototype |
|||
| Task |
|||
|- |
|||
| 30 |
|||
| LU decomposition |
|||
| Task |
|||
|- |
|||
| 30 |
|||
| GUI/Maximum window dimensions |
|||
| Task |
|||
|- |
|||
| 30 |
|||
| Numerical integration/Gauss-Legendre Quadrature |
|||
| Task |
|||
|- |
|||
| 30 |
|||
| Scope/Function names and labels |
|||
| Task |
|||
|- |
|||
| 30 |
|||
| Fibonacci word/fractal |
|||
| Task |
|||
|- |
|||
| 30 |
|||
| Ordered Partitions |
|||
| Task |
|||
|- |
|||
| 30 |
|||
| Casting out nines |
|||
| Task |
|||
|- |
|||
| 30 |
|||
| Cartesian product of two or more lists |
|||
| Task |
|||
|- |
|||
| 30 |
|||
| Permutations with repetitions |
|||
| Draft |
|||
|- |
|||
| 30 |
|||
| Speech synthesis |
|||
| Task |
|||
|- |
|||
| 30 |
|||
| Bitmap/Bézier curves/Cubic |
|||
| Task |
|||
|- |
|||
| 29 |
|||
| Input/Output for Pairs of Numbers |
|||
| Draft |
|||
|- |
|||
| 29 |
|||
| Julia set |
|||
| Task |
|||
|- |
|||
| 29 |
|||
| Conjugate transpose |
|||
| Task |
|||
|- |
|||
| 29 |
|||
| Bitmap/Histogram |
|||
| Task |
|||
|- |
|||
| 29 |
|||
| Maze solving |
|||
| Task |
|||
|- |
|||
| 29 |
|||
| Terminal control/Hiding the cursor |
|||
| Task |
|||
|- |
|||
| 28 |
|||
| Terminal control/Unicode output |
|||
| Task |
|||
|- |
|||
| 28 |
|||
| Executable library |
|||
| Task |
|||
|- |
|||
| 28 |
|||
| Topic variable |
|||
| Task |
|||
|- |
|||
| 28 |
|||
| Minesweeper game |
|||
| Task |
|||
|- |
|||
| 28 |
|||
| Simple database |
|||
| Task |
|||
|- |
|||
| 28 |
|||
| Bitwise IO |
|||
| Task |
|||
|- |
|||
| 28 |
|||
| Elementary cellular automaton |
|||
| Task |
|||
|- |
|||
| 28 |
|||
| Sutherland-Hodgman polygon clipping |
|||
| Task |
|||
|- |
|||
| 28 |
|||
| Find the intersection of two lines |
|||
| Task |
|||
|- |
|||
| 28 |
|||
| Object serialization |
|||
| Task |
|||
|- |
|||
| 28 |
|||
| Primorial numbers |
|||
| Task |
|||
|- |
|||
| 28 |
|||
| Water collected between towers |
|||
| Task |
|||
|- |
|||
| 28 |
|||
| Flipping bits game |
|||
| Task |
|||
|- |
|||
| 28 |
|||
| Parse command-line arguments |
|||
| Draft |
|||
|- |
|||
| 28 |
|||
| Bitmap/Bézier curves/Quadratic |
|||
| Task |
|||
|- |
|||
| 27 |
|||
| File extension is in extensions list |
|||
| Draft |
|||
|- |
|||
| 27 |
|||
| Penney's game |
|||
| Task |
|||
|- |
|||
| 27 |
|||
| Multiple regression |
|||
| Task |
|||
|- |
|||
| 27 |
|||
| Sattolo cycle |
|||
| Draft |
|||
|- |
|||
| 27 |
|||
| Input/Output for Lines of Text |
|||
| Draft |
|||
|- |
|||
| 27 |
|||
| Colour pinstripe/Display |
|||
| Task |
|||
|- |
|||
| 27 |
|||
| Bitcoin/address validation |
|||
| Task |
|||
|- |
|||
| 27 |
|||
| Pinstripe/Display |
|||
| Task |
|||
|- |
|||
| 26 |
|||
| Sailors, coconuts and a monkey problem |
|||
| Task |
|||
|- |
|||
| 26 |
|||
| RSA code |
|||
| Task |
|||
|- |
|||
| 26 |
|||
| Sorting Algorithms/Circle Sort |
|||
| Draft |
|||
|- |
|||
| 26 |
|||
| Memory layout of a data structure |
|||
| Task |
|||
|- |
|||
| 26 |
|||
| Zhang-Suen thinning algorithm |
|||
| Task |
|||
|- |
|||
| 26 |
|||
| Numeric error propagation |
|||
| Task |
|||
|- |
|||
| 26 |
|||
| Set puzzle |
|||
| Task |
|||
|- |
|||
| 26 |
|||
| Pathological floating point problems |
|||
| Task |
|||
|- |
|||
| 26 |
|||
| Ranking methods |
|||
| Task |
|||
|- |
|||
| 25 |
|||
| Update a configuration file |
|||
| Task |
|||
|- |
|||
| 25 |
|||
| Textonyms |
|||
| Task |
|||
|- |
|||
| 25 |
|||
| Straddling checkerboard |
|||
| Task |
|||
|- |
|||
| 25 |
|||
| Magic squares of doubly even order |
|||
| Task |
|||
|- |
|||
| 25 |
|||
| Formal power series |
|||
| Task |
|||
|- |
|||
| 25 |
|||
| Subset sum problem |
|||
| Draft |
|||
|- |
|||
| 25 |
|||
| Execute SNUSP |
|||
| Task |
|||
|- |
|||
| 25 |
|||
| Check output device is a terminal |
|||
| Draft |
|||
|- |
|||
| 25 |
|||
| Entropy/Narcissist |
|||
| Task |
|||
|- |
|||
| 25 |
|||
| State name puzzle |
|||
| Task |
|||
|- |
|||
| 25 |
|||
| Parametrized SQL statement |
|||
| Task |
|||
|- |
|||
| 25 |
|||
| Multiplicative order |
|||
| Task |
|||
|- |
|||
| 25 |
|||
| Arena storage pool |
|||
| Task |
|||
|- |
|||
| 25 |
|||
| Floyd-Warshall algorithm |
|||
| Task |
|||
|- |
|||
| 25 |
|||
|data-sort-value="ripemd-0D160"| RIPEMD-160 |
|||
| Task |
|||
|- |
|||
| 25 |
|||
| Continued fraction/Arithmetic/Construct from rational number |
|||
| Task |
|||
|- |
|||
| 25 |
|||
| Solve a Hidato puzzle |
|||
| Task |
|||
|- |
|||
| 25 |
|||
| QR decomposition |
|||
| Task |
|||
|- |
|||
| 25 |
|||
| Xiaolin Wu's line algorithm |
|||
| Task |
|||
|- |
|||
| 25 |
|||
| Same Fringe |
|||
| Task |
|||
|- |
|||
| 25 |
|||
|data-sort-value="read a file character by character/utf0B8"| Read a file character by character/UTF8 |
|||
| Draft |
|||
|- |
|||
| 25 |
|||
| First class environments |
|||
| Task |
|||
|- |
|||
| 25 |
|||
| Use another language to call a function |
|||
| Task |
|||
|- |
|||
| 25 |
|||
| Longest Common Substring |
|||
| Draft |
|||
|- |
|||
| 24 |
|||
| Brace expansion |
|||
| Task |
|||
|- |
|||
| 24 |
|||
| Egyptian division |
|||
| Task |
|||
|- |
|||
| 24 |
|||
| Musical scale |
|||
| Draft |
|||
|- |
|||
| 24 |
|||
|data-sort-value="deconvolution/0B1d"| Deconvolution/1D |
|||
| Task |
|||
|- |
|||
| 24 |
|||
| Distributed programming |
|||
| Task |
|||
|- |
|||
| 24 |
|||
| Rosetta Code/Fix code tags |
|||
| Task |
|||
|- |
|||
| 24 |
|||
| Sorting algorithms/Cycle sort |
|||
| Draft |
|||
|- |
|||
| 24 |
|||
| Metronome |
|||
| Task |
|||
|- |
|||
| 24 |
|||
| Resistor mesh |
|||
| Task |
|||
|- |
|||
| 24 |
|||
| Pragmatic directives |
|||
| Task |
|||
|- |
|||
| 24 |
|||
| Find palindromic numbers in both binary and ternary bases |
|||
| Task |
|||
|- |
|||
| 24 |
|||
| Chinese zodiac |
|||
| Task |
|||
|- |
|||
| 24 |
|||
| Rosetta Code/Find bare lang tags |
|||
| Task |
|||
|- |
|||
| 24 |
|||
| Keyboard macros |
|||
| Task |
|||
|- |
|||
| 23 |
|||
| Find first and last set bit of a long integer |
|||
| Draft |
|||
|- |
|||
| 23 |
|||
| Natural sorting |
|||
| Task |
|||
|- |
|||
| 23 |
|||
| Cramer's rule |
|||
| Task |
|||
|- |
|||
| 23 |
|||
| Solve the no connection puzzle |
|||
| Task |
|||
|- |
|||
| 23 |
|||
| Sort a list of object identifiers |
|||
| Task |
|||
|- |
|||
| 23 |
|||
| Paraffins |
|||
| Task |
|||
|- |
|||
| 23 |
|||
| Death Star |
|||
| Task |
|||
|- |
|||
| 23 |
|||
|data-sort-value="window creation/x0C11"| Window creation/X11 |
|||
| Task |
|||
|- |
|||
| 23 |
|||
| Pythagoras tree |
|||
| Task |
|||
|- |
|||
| 23 |
|||
| Lychrel numbers |
|||
| Task |
|||
|- |
|||
| 23 |
|||
| Arithmetic-geometric mean/Calculate Pi |
|||
| Task |
|||
|- |
|||
| 23 |
|||
| Truth table |
|||
| Task |
|||
|- |
|||
| 23 |
|||
| Pattern matching |
|||
| Task |
|||
|- |
|||
| 23 |
|||
| Sorting algorithms/Patience sort |
|||
| Draft |
|||
|- |
|||
| 22 |
|||
| Active Directory/Connect |
|||
| Task |
|||
|- |
|||
| 22 |
|||
| Create a file on magnetic tape |
|||
| Task |
|||
|- |
|||
| 22 |
|||
| Go Fish |
|||
| Task |
|||
|- |
|||
| 22 |
|||
| Terminal control/Cursor movement |
|||
| Task |
|||
|- |
|||
| 22 |
|||
| Word count |
|||
| Draft |
|||
|- |
|||
| 22 |
|||
| Rosetta Code/Find unimplemented tasks |
|||
| Task |
|||
|- |
|||
| 22 |
|||
| Galton box animation |
|||
| Task |
|||
|- |
|||
| 22 |
|||
| Text between |
|||
| Draft |
|||
|- |
|||
| 22 |
|||
| Prime conspiracy |
|||
| Draft |
|||
|- |
|||
| 22 |
|||
| FTP |
|||
| Task |
|||
|- |
|||
| 22 |
|||
| Write to Windows event log |
|||
| Task |
|||
|- |
|||
| 22 |
|||
| Check Machin-like formulas |
|||
| Task |
|||
|- |
|||
| 22 |
|||
| Angle difference between two bearings |
|||
| Task |
|||
|- |
|||
| 21 |
|||
|data-sort-value="utf-0B8 encode and decode"| UTF-8 encode and decode |
|||
| Task |
|||
|- |
|||
| 21 |
|||
| The ISAAC Cipher |
|||
| Task |
|||
|- |
|||
| 21 |
|||
| Welch's t-test |
|||
| Draft |
|||
|- |
|||
| 21 |
|||
| Find largest left truncatable prime in a given base |
|||
| Task |
|||
|- |
|||
| 21 |
|||
| Terminal control/Preserve screen |
|||
| Task |
|||
|- |
|||
| 21 |
|||
| Nautical bell |
|||
| Task |
|||
|- |
|||
| 21 |
|||
| Sum and Product Puzzle |
|||
| Task |
|||
|- |
|||
| 21 |
|||
| Verify distribution uniformity/Chi-squared test |
|||
| Task |
|||
|- |
|||
| 21 |
|||
| Currency |
|||
| Draft |
|||
|- |
|||
| 21 |
|||
| Check input device is a terminal |
|||
| Draft |
|||
|- |
|||
| 21 |
|||
| Checkpoint synchronization |
|||
| Task |
|||
|- |
|||
| 21 |
|||
| URL parser |
|||
| Task |
|||
|- |
|||
| 21 |
|||
| Implicit type conversion |
|||
| Draft |
|||
|- |
|||
| 21 |
|||
| Honeycombs |
|||
| Task |
|||
|- |
|||
| 21 |
|||
| Table creation |
|||
| Draft |
|||
|- |
|||
| 20 |
|||
| Pentagram |
|||
| Task |
|||
|- |
|||
| 20 |
|||
| Set of real numbers |
|||
| Task |
|||
|- |
|||
| 20 |
|||
| Permutations/Rank of a permutation |
|||
| Task |
|||
|- |
|||
| 20 |
|||
| Birthday problem |
|||
| Draft |
|||
|- |
|||
| 20 |
|||
| Multi-dimensional array |
|||
| Draft |
|||
|- |
|||
| 20 |
|||
| RCRPG |
|||
| Task |
|||
|- |
|||
| 20 |
|||
| Shoelace formula for polygonal area |
|||
| Task |
|||
|- |
|||
| 20 |
|||
| Substitution Cipher |
|||
| Draft |
|||
|- |
|||
| 20 |
|||
| Safe addition |
|||
| Task |
|||
|- |
|||
| 20 |
|||
| Partition an integer X into N primes |
|||
| Task |
|||
|- |
|||
| 20 |
|||
| Decimal floating point number to binary |
|||
| Draft |
|||
|- |
|||
| 20 |
|||
| Simulate input/Keyboard |
|||
| Task |
|||
|- |
|||
| 20 |
|||
| Ramsey's theorem |
|||
| Draft |
|||
|- |
|||
| 20 |
|||
| Image convolution |
|||
| Task |
|||
|- |
|||
| 20 |
|||
| Chat server |
|||
| Task |
|||
|- |
|||
| 20 |
|||
| Cycle detection |
|||
| Draft |
|||
|- |
|||
| 20 |
|||
| Function frequency |
|||
| Task |
|||
|- |
|||
| 20 |
|||
| Percolation/Mean run density |
|||
| Task |
|||
|- |
|||
| 20 |
|||
| Solve a Holy Knight's tour |
|||
| Task |
|||
|- |
|||
| 20 |
|||
| Play recorded sounds |
|||
| Task |
|||
|- |
|||
| 20 |
|||
| MAC Vendor Lookup |
|||
| Task |
|||
|- |
|||
| 19 |
|||
| Thiele's interpolation formula |
|||
| Task |
|||
|- |
|||
| 19 |
|||
| Total circles area |
|||
| Task |
|||
|- |
|||
| 19 |
|||
| Record sound |
|||
| Task |
|||
|- |
|||
| 19 |
|||
| Old Russian measure of length |
|||
| Draft |
|||
|- |
|||
| 19 |
|||
| Idiomatically determine all the lowercase and uppercase letters |
|||
| Draft |
|||
|- |
|||
| 19 |
|||
| Elliptic curve arithmetic |
|||
| Draft |
|||
|- |
|||
| 19 |
|||
| Damm algorithm |
|||
| Draft |
|||
|- |
|||
| 19 |
|||
| Yahoo! search interface |
|||
| Task |
|||
|- |
|||
| 19 |
|||
| Superellipse |
|||
| Task |
|||
|- |
|||
| 19 |
|||
| HTTPS/Authenticated |
|||
| Task |
|||
|- |
|||
| 19 |
|||
|data-sort-value="main step of gost 0F28147-0C89"| Main step of GOST 28147-89 |
|||
| Task |
|||
|- |
|||
| 19 |
|||
| Window management |
|||
| Task |
|||
|- |
|||
| 19 |
|||
| Cut a rectangle |
|||
| Task |
|||
|- |
|||
| 19 |
|||
| Decision tables |
|||
| Draft |
|||
|- |
|||
| 18 |
|||
| AVL tree |
|||
| Task |
|||
|- |
|||
| 18 |
|||
| K-means++ clustering |
|||
| Task |
|||
|- |
|||
| 18 |
|||
| Hough transform |
|||
| Task |
|||
|- |
|||
| 18 |
|||
| Egyptian fractions |
|||
| Task |
|||
|- |
|||
| 18 |
|||
| Create an object at a given address |
|||
| Task |
|||
|- |
|||
| 18 |
|||
| Stream Merge |
|||
| Task |
|||
|- |
|||
| 18 |
|||
| Reflection/List methods |
|||
| Draft |
|||
|- |
|||
| 18 |
|||
| Parse an IP Address |
|||
| Task |
|||
|- |
|||
| 18 |
|||
| Dice game probabilities |
|||
| Draft |
|||
|- |
|||
| 18 |
|||
| Make a backup file |
|||
| Draft |
|||
|- |
|||
| 18 |
|||
| Poker hand analyser |
|||
| Task |
|||
|- |
|||
| 17 |
|||
| Display a linear combination |
|||
| Draft |
|||
|- |
|||
| 17 |
|||
| Pig the dice game/Player |
|||
| Task |
|||
|- |
|||
| 17 |
|||
| Playfair cipher |
|||
| Draft |
|||
|- |
|||
| 17 |
|||
| SOAP |
|||
| Task |
|||
|- |
|||
| 17 |
|||
| Reflection/List properties |
|||
| Task |
|||
|- |
|||
| 17 |
|||
| Parallel Brute Force |
|||
| Task |
|||
|- |
|||
| 17 |
|||
| Polyspiral |
|||
| Task |
|||
|- |
|||
| 17 |
|||
| Modular arithmetic |
|||
| Draft |
|||
|- |
|||
| 17 |
|||
| Integer roots |
|||
| Draft |
|||
|- |
|||
| 17 |
|||
| Sequence of primorial primes |
|||
| Draft |
|||
|- |
|||
| 17 |
|||
| Draw a rotating cube |
|||
| Task |
|||
|- |
|||
| 17 |
|||
| Sokoban |
|||
| Task |
|||
|- |
|||
| 17 |
|||
| Plasma effect |
|||
| Task |
|||
|- |
|||
| 16 |
|||
| Kahan summation |
|||
| Draft |
|||
|- |
|||
| 16 |
|||
| Kronecker product based fractals |
|||
| Task |
|||
|- |
|||
| 16 |
|||
| Median filter |
|||
| Task |
|||
|- |
|||
| 16 |
|||
| Simulate input/Mouse |
|||
| Task |
|||
|- |
|||
| 16 |
|||
| Pythagorean quadruples |
|||
| Task |
|||
|- |
|||
| 16 |
|||
| Linux CPU utilization |
|||
| Draft |
|||
|- |
|||
| 16 |
|||
| Perlin noise |
|||
| Draft |
|||
|- |
|||
| 16 |
|||
| Elementary cellular automaton/Random Number Generator |
|||
| Draft |
|||
|- |
|||
| 16 |
|||
| Idiomatically determine all the characters that can be used for symbols |
|||
| Draft |
|||
|- |
|||
| 15 |
|||
| Machine code |
|||
| Task |
|||
|- |
|||
| 15 |
|||
| Active Directory/Search for a user |
|||
| Task |
|||
|- |
|||
| 15 |
|||
| Levenshtein distance/Alignment |
|||
| Draft |
|||
|- |
|||
| 15 |
|||
| Solve a Numbrix puzzle |
|||
| Task |
|||
|- |
|||
| 15 |
|||
| Compiler/lexical analyzer |
|||
| Task |
|||
|- |
|||
| 15 |
|||
| Bacon cipher |
|||
| Draft |
|||
|- |
|||
| 15 |
|||
| Card shuffles |
|||
| Draft |
|||
|- |
|||
| 14 |
|||
| Negative base numbers |
|||
| Task |
|||
|- |
|||
| 14 |
|||
| Faulhaber's formula |
|||
| Draft |
|||
|- |
|||
| 14 |
|||
| Elementary cellular automaton/Infinite length |
|||
| Draft |
|||
|- |
|||
| 14 |
|||
| Deming's Funnel |
|||
| Draft |
|||
|- |
|||
| 14 |
|||
| Magic squares of singly even order |
|||
| Task |
|||
|- |
|||
| 14 |
|||
| Names to numbers |
|||
| Draft |
|||
|- |
|||
| 14 |
|||
| Reverse the gender of a string |
|||
| Draft |
|||
|- |
|||
| 14 |
|||
| World Cup group stage |
|||
| Task |
|||
|- |
|||
| 14 |
|||
| Solve a Hopido puzzle |
|||
| Task |
|||
|- |
|||
| 14 |
|||
| Chebyshev coefficients |
|||
| Draft |
|||
|- |
|||
| 14 |
|||
| K-d tree |
|||
| Task |
|||
|- |
|||
| 14 |
|||
| Native shebang |
|||
| Draft |
|||
|- |
|||
| 14 |
|||
| Selective File Copy |
|||
| Draft |
|||
|- |
|||
| 14 |
|||
| Assertions in design by contract |
|||
| Draft |
|||
|- |
|||
| 14 |
|||
| Tonelli-Shanks algorithm |
|||
| Draft |
|||
|- |
|||
| 14 |
|||
| AudioAlarm |
|||
| Draft |
|||
|- |
|||
| 14 |
|||
| Vigenère cipher/Cryptanalysis |
|||
| Task |
|||
|- |
|||
| 14 |
|||
| Index finite lists of positive integers |
|||
| Draft |
|||
|- |
|||
| 13 |
|||
| SQL-based authentication |
|||
| Task |
|||
|- |
|||
| 13 |
|||
| Bitcoin/public point to address |
|||
| Task |
|||
|- |
|||
| 13 |
|||
| Type detection |
|||
| Draft |
|||
|- |
|||
| 13 |
|||
| Terminal control/Positional read |
|||
| Task |
|||
|- |
|||
| 13 |
|||
| Color quantization |
|||
| Task |
|||
|- |
|||
| 13 |
|||
| Sierpinski pentagon |
|||
| Task |
|||
|- |
|||
| 13 |
|||
| A* search algorithm |
|||
| Draft |
|||
|- |
|||
| 13 |
|||
| Create an object/Native demonstration |
|||
| Draft |
|||
|- |
|||
| 13 |
|||
| Nonoblock |
|||
| Task |
|||
|- |
|||
| 13 |
|||
| Video display modes |
|||
| Task |
|||
|- |
|||
| 13 |
|||
| Apply a digital filter (direct form II transposed) |
|||
| Task |
|||
|- |
|||
| 13 |
|||
| Rendezvous |
|||
| Task |
|||
|- |
|||
| 13 |
|||
| Superpermutation minimisation |
|||
| Draft |
|||
|- |
|||
| 13 |
|||
| Cipolla's algorithm |
|||
| Draft |
|||
|- |
|||
| 13 |
|||
| Fivenum |
|||
| Draft |
|||
|- |
|||
| 13 |
|||
| Percolation/Site percolation |
|||
| Task |
|||
|- |
|||
| 12 |
|||
| Retrieve and search chat history |
|||
| Task |
|||
|- |
|||
| 12 |
|||
| Diversity prediction theorem |
|||
| Draft |
|||
|- |
|||
| 12 |
|||
| Percolation/Bond percolation |
|||
| Task |
|||
|- |
|||
| 12 |
|||
| Lucky and even lucky numbers |
|||
| Task |
|||
|- |
|||
| 12 |
|||
| Most frequent k chars distance |
|||
| Draft |
|||
|- |
|||
| 12 |
|||
| Untrusted environment |
|||
| Draft |
|||
|- |
|||
| 12 |
|||
| Percolation/Mean cluster density |
|||
| Task |
|||
|- |
|||
| 12 |
|||
| Reflection/Get source |
|||
| Task |
|||
|- |
|||
| 12 |
|||
| Word break problem |
|||
| Draft |
|||
|- |
|||
| 12 |
|||
| Joystick position |
|||
| Task |
|||
|- |
|||
| 12 |
|||
| Bitmap/Read an image through a pipe |
|||
| Task |
|||
|- |
|||
| 12 |
|||
| I.Q. Puzzle |
|||
| Draft |
|||
|- |
|||
| 12 |
|||
| Convex hull |
|||
| Draft |
|||
|- |
|||
| 11 |
|||
| Find URI in text |
|||
| Draft |
|||
|- |
|||
| 11 |
|||
| NYSIIS |
|||
| Draft |
|||
|- |
|||
| 11 |
|||
| Knuth's power tree |
|||
| Draft |
|||
|- |
|||
| 11 |
|||
| Faulhaber's triangle |
|||
| Draft |
|||
|- |
|||
| 11 |
|||
| Polynomial synthetic division |
|||
| Draft |
|||
|- |
|||
| 11 |
|||
| Arithmetic coding/As a generalized change of radix |
|||
| Draft |
|||
|- |
|||
| 11 |
|||
| Monads/Maybe monad |
|||
| Draft |
|||
|- |
|||
| 11 |
|||
| Shortest common supersequence |
|||
| Draft |
|||
|- |
|||
| 11 |
|||
| Ramer-Douglas-Peucker line simplification |
|||
| Task |
|||
|- |
|||
| 11 |
|||
| Bilinear interpolation |
|||
| Draft |
|||
|- |
|||
| 11 |
|||
| List rooted trees |
|||
| Draft |
|||
|- |
|||
| 11 |
|||
| Vogel's approximation method |
|||
| Task |
|||
|- |
|||
| 11 |
|||
| N-body problem |
|||
| Draft |
|||
|- |
|||
| 11 |
|||
| Proof |
|||
| Draft |
|||
|- |
|||
| 11 |
|||
| Compare sorting algorithms' performance |
|||
| Task |
|||
|- |
|||
| 11 |
|||
| Find the intersection of a line with a plane |
|||
| Task |
|||
|- |
|||
| 11 |
|||
| Separate the house number from the street name |
|||
| Draft |
|||
|- |
|||
| 10 |
|||
| Find duplicate files |
|||
| Draft |
|||
|- |
|||
| 10 |
|||
| P-value correction |
|||
| Draft |
|||
|- |
|||
| 10 |
|||
| Generate random chess position |
|||
| Draft |
|||
|- |
|||
| 10 |
|||
| Commatizing numbers |
|||
| Task |
|||
|- |
|||
| 10 |
|||
| Mersenne primes |
|||
| Draft |
|||
|- |
|||
| 10 |
|||
| Monads/List monad |
|||
| Draft |
|||
|- |
|||
| 10 |
|||
| Zeckendorf arithmetic |
|||
| Task |
|||
|- |
|||
| 10 |
|||
| Aspect Oriented Programming |
|||
| Draft |
|||
|- |
|||
| 10 |
|||
| Nonogram solver |
|||
| Task |
|||
|- |
|||
| 10 |
|||
| Markov chain text generator |
|||
| Draft |
|||
|- |
|||
| 10 |
|||
| Determine if two triangles overlap |
|||
| Draft |
|||
|- |
|||
| 10 |
|||
| Readline interface |
|||
| Draft |
|||
|- |
|||
| 10 |
|||
| Snake |
|||
| Draft |
|||
|- |
|||
| 10 |
|||
| Primes - allocate descendants to their ancestors |
|||
| Task |
|||
|- |
|||
| 10 |
|||
| Compiler/virtual machine interpreter |
|||
| Task |
|||
|- |
|||
| 10 |
|||
| HTTPS/Client-authenticated |
|||
| Task |
|||
|- |
|||
| 10 |
|||
| Compiler/code generator |
|||
| Task |
|||
|- |
|||
| 10 |
|||
| Topological sort/Extracted top item |
|||
| Draft |
|||
|- |
|||
| 9 |
|||
| Bitmap/PPM conversion through a pipe |
|||
| Task |
|||
|- |
|||
| 9 |
|||
| XML Validation |
|||
| Draft |
|||
|- |
|||
| 9 |
|||
| Suffix tree |
|||
| Draft |
|||
|- |
|||
| 9 |
|||
|data-sort-value="base0C58check encoding"| Base58Check encoding |
|||
| Draft |
|||
|- |
|||
| 9 |
|||
| Eertree |
|||
| Task |
|||
|- |
|||
| 9 |
|||
| VList |
|||
| Draft |
|||
|- |
|||
| 9 |
|||
| Code segment unload |
|||
| Draft |
|||
|- |
|||
| 9 |
|||
| Word search |
|||
| Task |
|||
|- |
|||
| 9 |
|||
| Transportation problem |
|||
| Draft |
|||
|- |
|||
| 9 |
|||
| Abbreviations, automatic |
|||
| Draft |
|||
|- |
|||
| 9 |
|||
| File size distribution |
|||
| Draft |
|||
|- |
|||
| 9 |
|||
| Four is magic |
|||
| Draft |
|||
|- |
|||
| 9 |
|||
| Color wheel |
|||
| Draft |
|||
|- |
|||
| 9 |
|||
| Free polyominoes enumeration |
|||
| Draft |
|||
|- |
|||
| 9 |
|||
| Continued fraction/Arithmetic/G(matrix NG, Contined Fraction N) |
|||
| Draft |
|||
|- |
|||
| 8 |
|||
| Compiler/AST interpreter |
|||
| Task |
|||
|- |
|||
| 8 |
|||
| Self-hosting compiler |
|||
| Draft |
|||
|- |
|||
| 8 |
|||
| Loops/Increment loop index within loop body |
|||
| Draft |
|||
|- |
|||
| 8 |
|||
| Hunt The Wumpus |
|||
| Task |
|||
|- |
|||
| 8 |
|||
| Montgomery reduction |
|||
| Draft |
|||
|- |
|||
| 8 |
|||
| Kosaraju |
|||
| Draft |
|||
|- |
|||
| 8 |
|||
| Largest number divisible by its digits |
|||
| Draft |
|||
|- |
|||
| 8 |
|||
| Perceptron |
|||
| Draft |
|||
|- |
|||
| 8 |
|||
| Compiler/syntax analyzer |
|||
| Task |
|||
|- |
|||
| 8 |
|||
| Finite state machine |
|||
| Draft |
|||
|- |
|||
| 7 |
|||
| Run as a daemon or service |
|||
| Draft |
|||
|- |
|||
| 7 |
|||
| Mastermind |
|||
| Draft |
|||
|- |
|||
| 7 |
|||
| Time-based One-time Password Algorithm |
|||
| Draft |
|||
|- |
|||
| 7 |
|||
| Particle Swarm Optimization |
|||
| Draft |
|||
|- |
|||
| 7 |
|||
| The Name Game |
|||
| Task |
|||
|- |
|||
| 7 |
|||
| Generalised floating point addition |
|||
| Draft |
|||
|- |
|||
| 7 |
|||
| Singly-linked list/Element removal |
|||
| Draft |
|||
|- |
|||
| 7 |
|||
|data-sort-value="deconvolution/0B2d+"| Deconvolution/2D+ |
|||
| Task |
|||
|- |
|||
| 7 |
|||
| Orbital elements |
|||
| Draft |
|||
|- |
|||
| 7 |
|||
| Canny edge detector |
|||
| Task |
|||
|- |
|||
| 7 |
|||
| Abbreviations, easy |
|||
| Draft |
|||
|- |
|||
| 7 |
|||
| User defined pipe and redirection operators |
|||
| Draft |
|||
|- |
|||
| 7 |
|||
| IPC via named pipe |
|||
| Draft |
|||
|- |
|||
| 7 |
|||
| Monads/Writer monad |
|||
| Draft |
|||
|- |
|||
| 6 |
|||
| Just in time processing on a character stream |
|||
| Draft |
|||
|- |
|||
| 6 |
|||
| Catmull–Clark subdivision surface |
|||
| Task |
|||
|- |
|||
| 6 |
|||
| French Republican calendar |
|||
| Draft |
|||
|- |
|||
| 6 |
|||
| Parse EBNF |
|||
| Draft |
|||
|- |
|||
| 6 |
|||
| Addition chains |
|||
| Draft |
|||
|- |
|||
| 6 |
|||
| Morpion solitaire |
|||
| Draft |
|||
|- |
|||
| 6 |
|||
| Banker's algorithm |
|||
| Draft |
|||
|- |
|||
| 5 |
|||
| Spelling of ordinal numbers |
|||
| Draft |
|||
|- |
|||
| 5 |
|||
| Sorting algorithms/Tree sort on a linked list |
|||
| Draft |
|||
|- |
|||
| 5 |
|||
| Combinations with repetitions/Square Digit Chain |
|||
| Draft |
|||
|- |
|||
| 5 |
|||
| Abbreviations, simple |
|||
| Draft |
|||
|- |
|||
| 5 |
|||
| Audio frequency generator |
|||
| Draft |
|||
|- |
|||
| 5 |
|||
| Imaginary base numbers |
|||
| Draft |
|||
|- |
|||
| 5 |
|||
| ASCII art diagram converter |
|||
| Draft |
|||
|- |
|||
| 5 |
|||
| Pinstripe/Printer |
|||
| Task |
|||
|- |
|||
| 5 |
|||
| Starting a web browser |
|||
| Draft |
|||
|- |
|||
| 5 |
|||
| OpenGL Pixel Shader |
|||
| Draft |
|||
|- |
|||
| 4 |
|||
| Using the Meetup.com API |
|||
| Draft |
|||
|- |
|||
| 4 |
|||
|data-sort-value="0C15 puzzle solver"| 15 puzzle solver |
|||
| Task |
|||
|- |
|||
| 4 |
|||
| Snake And Ladder |
|||
| Draft |
|||
|- |
|||
| 4 |
|||
| Gauss-Jordan matrix inversion |
|||
| Draft |
|||
|- |
|||
| 4 |
|||
|data-sort-value="continued fraction/arithmetic/g(matrix ng, contined fraction n0B1, contined fraction n0B2)"| Continued fraction/Arithmetic/G(matrix NG, Contined Fraction N1, Contined Fraction N2) |
|||
| Draft |
|||
|- |
|||
| 4 |
|||
| Four is the number of letters in the ... |
|||
| Draft |
|||
|- |
|||
| 4 |
|||
| Geometric algebra |
|||
| Draft |
|||
|- |
|||
| 4 |
|||
| Data Encryption Standard |
|||
| Draft |
|||
|- |
|||
| 4 |
|||
| Tetris |
|||
| Draft |
|||
|- |
|||
| 4 |
|||
| Pentomino tiling |
|||
| Draft |
|||
|- |
|||
| 4 |
|||
| Fibonacci heap |
|||
| Draft |
|||
|- |
|||
| 4 |
|||
| Remote agent/Agent interface |
|||
| Draft |
|||
|- |
|||
| 4 |
|||
| Functional coverage tree |
|||
| Draft |
|||
|- |
|||
| 4 |
|||
| Greed |
|||
| Draft |
|||
|- |
|||
| 4 |
|||
| Addition-chain exponentiation |
|||
| Draft |
|||
|- |
|||
| 4 |
|||
| Rosetta Code/Run examples |
|||
| Draft |
|||
|- |
|||
| 4 |
|||
| Remote agent/Simulation |
|||
| Draft |
|||
|- |
|||
| 4 |
|||
| Colour pinstripe/Printer |
|||
| Task |
|||
|- |
|||
| 4 |
|||
| Remote agent/Agent logic |
|||
| Draft |
|||
|- |
|||
| 4 |
|||
| Railway circuit |
|||
| Draft |
|||
|- |
|||
| 4 |
|||
| Using a Speech engine to highlight words |
|||
| Draft |
|||
|- |
|||
| 4 |
|||
| One-time pad |
|||
| Draft |
|||
|- |
|||
| 4 |
|||
| Tarjan |
|||
| Draft |
|||
|- |
|||
| 3 |
|||
| Hexapawn |
|||
| Draft |
|||
|- |
|||
| 3 |
|||
| OpenGL/Utah Teapot |
|||
| Draft |
|||
|- |
|||
| 3 |
|||
| Rosetta Code/Rank languages by number of users |
|||
| Draft |
|||
|- |
|||
| 3 |
|||
| Robots |
|||
| Draft |
|||
|- |
|||
| 3 |
|||
| Boids |
|||
| Draft |
|||
|- |
|||
| 3 |
|||
| Text to HTML |
|||
| Draft |
|||
|- |
|||
| 3 |
|||
| Rosetta Code/Tasks without examples |
|||
| Draft |
|||
|- |
|||
| 3 |
|||
| Simulated annealing |
|||
| Draft |
|||
|- |
|||
| 2 |
|||
| Recursive descent parser generator |
|||
| Draft |
|||
|- |
|||
| 2 |
|||
| Tamagotchi emulator |
|||
| Draft |
|||
|- |
|||
| 2 |
|||
| OpenWebNet Password |
|||
| Draft |
|||
|- |
|||
| 2 |
|||
| Solve a Rubik's Cube |
|||
| Draft |
|||
|- |
|||
| 2 |
|||
| External sort |
|||
| Draft |
|||
|- |
|||
| 2 |
|||
| OLE Automation |
|||
| Task |
|||
|- |
|||
| 2 |
|||
| Audio Overlap Loop |
|||
| Draft |
|||
|- |
|||
| 2 |
|||
| Chess player |
|||
| Draft |
|||
|- |
|||
| 2 |
|||
| Penrose tiling |
|||
| Draft |
|||
|- |
|||
| 1 |
|||
| Terminal control/Restricted width positional input/With wrapping |
|||
| Draft |
|||
|- |
|||
| 1 |
|||
| Solving coin problems |
|||
| Draft |
|||
|- |
|||
| 1 |
|||
| Generalised floating point multiplication |
|||
| Draft |
|||
|- |
|||
| 1 |
|||
| Multidimensional Newton-Raphson metod |
|||
| Draft |
|||
|- |
|||
| 1 |
|||
| Terminal control/Restricted width positional input/No wrapping |
|||
| Draft |
|||
|- |
|||
| 1 |
|||
| IRC gateway |
|||
| Draft |
|||
|- |
|||
| 1 |
|||
| Rosetta Code/List authors of task descriptions |
|||
| Draft |
|||
|- |
|||
| 1 |
|||
| Process SMIL directives in XML data |
|||
| Draft |
|||
|- |
|||
| 1 |
|||
| Black Box |
|||
| Draft |
|||
|- |
|||
| 0 |
|||
| Waveform analysis/Doh ray me |
|||
| Draft |
|||
|- |
|||
| 0 |
|||
| Rosetta Code/Tasks sorted by average lines of code |
|||
| Draft |
|||
|- |
|||
| 0 |
|||
| Waveform analysis/Top and tail |
|||
| Draft |
|||
|- |
|||
| 0 |
|||
| Ukkonen’s Suffix Tree Construction |
|||
| Draft |
|||
|- |
|||
| 0 |
|||
| Weather Routing |
|||
| Draft |
|||
|- |
|||
| 0 |
|||
| Chess player/Search and evaluation |
|||
| Draft |
|||
|- |
|||
| 0 |
|||
| Blackjack strategy |
|||
| Draft |
|||
|- |
|||
| 0 |
|||
| Chess player/Program options and user interface |
|||
| Draft |
|||
|- |
|||
| 0 |
|||
| Chess player/Move generation |
|||
| Draft |
|||
|- |
|||
| 0 |
|||
| Unicode polynomial equation |
|||
| Draft |
|||
|} |
|||
</div> |
|||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
< |
<syntaxhighlight lang="picolisp">(load "@lib/http.l") |
||
(client "rosettacode.org" 80 |
(client "rosettacode.org" 80 |
||
Line 6,085: | Line 2,153: | ||
(unless (sub? "." (till "<" T)) |
(unless (sub? "." (till "<" T)) |
||
(inc 'Cnt) ) ) |
(inc 'Cnt) ) ) |
||
(out NIL (prinl (ht:Pack Task) ": " Cnt)) ) ) ) ) )</ |
(out NIL (prinl (ht:Pack Task) ": " Cnt)) ) ) ) ) )</syntaxhighlight> |
||
Output (05may10): |
Output (05may10): |
||
<pre>100 doors: 79 |
<pre>100 doors: 79 |
||
Line 6,094: | Line 2,162: | ||
Abstract type: 29 |
Abstract type: 29 |
||
...</pre> |
...</pre> |
||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |
||
< |
<syntaxhighlight lang="purebasic">Procedure handleError(value, msg.s) |
||
If value = 0 |
If value = 0 |
||
MessageRequester("Error", msg) |
MessageRequester("Error", msg) |
||
Line 6,160: | Line 2,227: | ||
Input() |
Input() |
||
CloseConsole() |
CloseConsole() |
||
EndIf</ |
EndIf</syntaxhighlight> |
||
Sample output: |
Sample output: |
||
<pre>100 doors: 224 examples |
<pre>100 doors: 224 examples |
||
Line 6,178: | Line 2,245: | ||
=={{header|Python}}== |
=={{header|Python}}== |
||
< |
<syntaxhighlight lang="python">from urllib.request import urlopen, Request |
||
import xml.dom.minidom |
|||
r = Request( |
|||
x = urllib.urlopen("http://www.rosettacode.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml") |
|||
'https://www.rosettacode.org/mw/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml', |
|||
headers={'User-Agent': 'Mozilla/5.0'}) |
|||
x = urlopen(r) |
|||
tasks = [] |
tasks = [] |
||
for i in xml.dom.minidom.parseString(x.read()).getElementsByTagName( |
for i in xml.dom.minidom.parseString(x.read()).getElementsByTagName('cm'): |
||
t = i.getAttribute('title').replace( |
t = i.getAttribute('title').replace(' ', '_') |
||
r = Request(f'https://www.rosettacode.org/mw/index.php?title={t}&action=raw', |
|||
headers={'User-Agent': 'Mozilla/5.0'}) |
|||
tasks.append( y.read().lower().count("{{header|") ) |
|||
y = urlopen(r) |
|||
print t.replace("_", " ") + ": %d examples." % tasks[-1] |
|||
tasks.append( y.read().lower().count(b'{{header|') ) |
|||
print(t.replace('_', ' ') + f': {tasks[-1]} examples.') |
|||
print |
print(f'\nTotal: {sum(tasks)} examples.') |
||
</syntaxhighlight> |
|||
===Using Semantic MediaWiki=== |
|||
{{libheader|Requests}} |
|||
Here we use the [https://www.semantic-mediawiki.org/wiki/Help:API:ask ask] API provided by the [https://www.semantic-mediawiki.org/wiki/Semantic_MediaWiki Semantic MediaWiki extension] to query page [https://www.semantic-mediawiki.org/wiki/Help:Properties_and_types properties] rather than parse page content, producing subtly different counts to some other solutions. Maybe too different for this task. |
|||
We only count task examples that have a corresponding category page AND that page has the "Is Language" property set to True. In other words, <code>Implemented In</code> + <code>Not Implemented In</code> + <code>Omitted From</code> is always equal to the total number of languages. |
|||
<syntaxhighlight lang="python">"""Count Rosetta Code tasks implementations using the Semantic MediaWiki API. |
|||
Works with Python >= 3.7.""" |
|||
import json |
|||
import logging |
|||
from dataclasses import dataclass |
|||
from dataclasses import field |
|||
from datetime import datetime |
|||
from typing import Any |
|||
from typing import Dict |
|||
from typing import List |
|||
from typing import Optional |
|||
from typing import Set |
|||
from typing import Tuple |
|||
import requests |
|||
from requests.adapters import HTTPAdapter |
|||
from requests.adapters import Retry |
|||
logging.basicConfig(level=logging.WARN) |
|||
# See https://www.semantic-mediawiki.org/wiki/Help:API:ask |
|||
_SM_ASK: Dict[str, str] = { |
|||
"action": "ask", |
|||
"format": "json", |
|||
"formatversion": "2", |
|||
"api_version": "3", |
|||
} |
|||
_SM_ASK_REQUEST_BLOCK_SIZE = 500 |
|||
@dataclass(frozen=True) |
|||
class Page: |
|||
# fulltext is the page's title, not the page content. |
|||
fulltext: str |
|||
fullurl: str |
|||
namespace: int |
|||
exists: str |
|||
displaytitle: str |
|||
@dataclass(frozen=True, eq=False) |
|||
class Lang(Page): |
|||
def __eq__(self, other: object) -> bool: |
|||
if isinstance(other, Lang): |
|||
return self.fullurl == other.fullurl |
|||
elif isinstance(other, str): |
|||
return self.fullurl == other |
|||
return False |
|||
def __hash__(self) -> int: |
|||
return hash(self.fullurl) |
|||
def unimplemented(self, tasks: Set["Task"]) -> Set["Task"]: |
|||
return {task for task in tasks if self.fullurl not in task.exclude} |
|||
def omitted_from(self, tasks: Set["Task"]) -> Set["Task"]: |
|||
return {task for task in tasks if self.fullurl in task.omitted_from} |
|||
@dataclass(frozen=True) |
|||
class Task(Page): |
|||
title: str |
|||
implemented_in: Set[Lang] = field(repr=False, compare=False) |
|||
omitted_from: Set[Lang] = field(repr=False, compare=False) |
|||
exclude: Set[Lang] = field(repr=False, compare=False) |
|||
def not_implemented_in(self, langs: Set[Lang]) -> Set[Lang]: |
|||
return langs.difference(self.exclude) |
|||
@dataclass |
|||
class TaskResponseBlock: |
|||
tasks: List[Task] |
|||
continue_offset: Optional[int] = None |
|||
@dataclass |
|||
class LanguageResponseBlock: |
|||
langs: List[Lang] |
|||
continue_offset: Optional[int] = None |
|||
def sm_ask_category( |
|||
session: requests.Session, |
|||
url: str, |
|||
category: str, |
|||
limit: int, |
|||
offset: int, |
|||
known_langs: Set[Lang], |
|||
) -> TaskResponseBlock: |
|||
query_params = { |
|||
**_SM_ASK, |
|||
"query": ( |
|||
f"[[Category:{category}]]" |
|||
"|?Implemented in language" |
|||
"|?Omitted from language" |
|||
f"|limit={limit}" |
|||
f"|offset={offset}" |
|||
), |
|||
} |
|||
# Display some progress |
|||
log(f"ask [[Category:{category}]] offset={offset}") |
|||
response = session.get(url, params=query_params) |
|||
response.raise_for_status() |
|||
data = response.json() |
|||
handle_warnings_and_errors(data) |
|||
return _transform_implemented_in_response_data(data, known_langs) |
|||
def sm_ask_tasks( |
|||
session: requests.Session, |
|||
url: str, |
|||
limit: int, |
|||
offset: int, |
|||
known_langs: Set[Lang], |
|||
): |
|||
return sm_ask_category( |
|||
session, url, "Programming Tasks", limit, offset, known_langs |
|||
) |
|||
def sm_ask_drafts( |
|||
session: requests.Session, |
|||
url: str, |
|||
limit: int, |
|||
offset: int, |
|||
known_langs: Set[Lang], |
|||
): |
|||
return sm_ask_category( |
|||
session, url, "Draft Programming Tasks", limit, offset, known_langs |
|||
) |
|||
def sm_ask_languages( |
|||
session: requests.Session, |
|||
url: str, |
|||
limit: int, |
|||
offset: int, |
|||
) -> LanguageResponseBlock: |
|||
query_params = { |
|||
**_SM_ASK, |
|||
"query": ( |
|||
"[[Is language::+]]" |
|||
"|?Implemented in language" |
|||
"|?Omitted from language" |
|||
f"|limit={limit}" |
|||
f"|offset={offset}" |
|||
), |
|||
} |
|||
# Display some progress |
|||
log(f"ask [[Is language::+]] offset={offset}") |
|||
response = session.get(url, params=query_params) |
|||
response.raise_for_status() |
|||
data = response.json() |
|||
handle_warnings_and_errors(data) |
|||
return _transform_language_response_data(data) |
|||
def sm_ask_all_tasks( |
|||
session: requests.Session, url: str, known_langs: Set[Lang] |
|||
) -> List[Task]: |
|||
block = sm_ask_tasks( |
|||
session, |
|||
url, |
|||
limit=_SM_ASK_REQUEST_BLOCK_SIZE, |
|||
offset=0, |
|||
known_langs=known_langs, |
|||
) |
|||
tasks = block.tasks |
|||
while block.continue_offset: |
|||
block = sm_ask_tasks( |
|||
session, |
|||
url, |
|||
limit=_SM_ASK_REQUEST_BLOCK_SIZE, |
|||
offset=block.continue_offset, |
|||
known_langs=known_langs, |
|||
) |
|||
tasks.extend(block.tasks) |
|||
return tasks |
|||
def sm_ask_all_drafts( |
|||
session: requests.Session, url: str, known_langs: Set[Lang] |
|||
) -> List[Task]: |
|||
block = sm_ask_drafts( |
|||
session, |
|||
url, |
|||
limit=_SM_ASK_REQUEST_BLOCK_SIZE, |
|||
offset=0, |
|||
known_langs=known_langs, |
|||
) |
|||
tasks = block.tasks |
|||
while block.continue_offset: |
|||
block = sm_ask_drafts( |
|||
session, |
|||
url, |
|||
limit=_SM_ASK_REQUEST_BLOCK_SIZE, |
|||
offset=block.continue_offset, |
|||
known_langs=known_langs, |
|||
) |
|||
tasks.extend(block.tasks) |
|||
return tasks |
|||
def sm_ask_all_languages(session: requests.Session, url: str) -> List[Lang]: |
|||
block = sm_ask_languages( |
|||
session, |
|||
url, |
|||
limit=_SM_ASK_REQUEST_BLOCK_SIZE, |
|||
offset=0, |
|||
) |
|||
langs = block.langs |
|||
while block.continue_offset: |
|||
block = sm_ask_languages( |
|||
session, |
|||
url, |
|||
limit=_SM_ASK_REQUEST_BLOCK_SIZE, |
|||
offset=block.continue_offset, |
|||
) |
|||
langs.extend(block.langs) |
|||
return langs |
|||
def _transform_implemented_in_response_data( |
|||
data: Any, known_langs: Set[Lang] |
|||
) -> TaskResponseBlock: |
|||
tasks: List[Task] = [] |
|||
for result in data["query"]["results"]: |
|||
for task_title, task_page in result.items(): |
|||
# We're excluding implementations that don't have a corresponding |
|||
# category page with an "Is Language" property. |
|||
implemented_in = { |
|||
Lang(**lang) |
|||
for lang in task_page["printouts"]["Implemented in language"] |
|||
}.intersection(known_langs) |
|||
omitted_from = ( |
|||
{ |
|||
Lang(**lang) |
|||
for lang in task_page["printouts"]["Omitted from language"] |
|||
} |
|||
.intersection(known_langs) |
|||
.difference(implemented_in) |
|||
) |
|||
tasks.append( |
|||
Task( |
|||
title=task_title, |
|||
implemented_in=implemented_in, |
|||
omitted_from=omitted_from, |
|||
fulltext=task_page["fulltext"], |
|||
fullurl=task_page["fullurl"], |
|||
namespace=task_page["namespace"], |
|||
exists=task_page["exists"], |
|||
displaytitle=task_page["displaytitle"], |
|||
exclude=implemented_in.union(omitted_from), |
|||
) |
|||
) |
|||
return TaskResponseBlock( |
|||
tasks=tasks, continue_offset=data.get("query-continue-offset", None) |
|||
) |
|||
def _transform_language_response_data(data: Any) -> LanguageResponseBlock: |
|||
langs: List[Lang] = [] |
|||
for result in data["query"]["results"]: |
|||
for _, task_page in result.items(): |
|||
langs.append( |
|||
Lang( |
|||
fulltext=task_page["fulltext"], |
|||
fullurl=task_page["fullurl"], |
|||
namespace=task_page["namespace"], |
|||
exists=task_page["exists"], |
|||
displaytitle=task_page["displaytitle"], |
|||
) |
|||
) |
|||
return LanguageResponseBlock( |
|||
langs=langs, continue_offset=data.get("query-continue-offset", None) |
|||
) |
|||
def get_session() -> requests.Session: |
|||
"""Setup a requests.Session with retries.""" |
|||
retry_strategy = Retry( |
|||
total=5, |
|||
status_forcelist=[429, 500, 502, 503, 504], |
|||
allowed_methods=["HEAD", "GET", "OPTIONS"], |
|||
) |
|||
adapter = HTTPAdapter(max_retries=retry_strategy) |
|||
session = requests.Session() |
|||
session.mount("https://", adapter) |
|||
session.mount("http://", adapter) |
|||
return session |
|||
def log(msg: str) -> None: |
|||
print(f"{datetime.now().isoformat(' ', 'seconds')}: {msg}") |
|||
def handle_warnings_and_errors(data: Any) -> None: |
|||
if data.get("errors"): |
|||
for error in data["errors"]: |
|||
logging.error(json.dumps(error)) |
|||
# legacy format |
|||
if data.get("error"): |
|||
logging.error(json.dumps(data["error"])) |
|||
if data.get("warnings"): |
|||
for warning in data["warnings"]: |
|||
logging.warning(json.dumps(warning)) |
|||
def count_examples(url: str, n: int = 30) -> None: |
|||
"""Print a table to stdout containing implementation counts for the first |
|||
`n` tasks, sorted by number implementations (most to least).""" |
|||
session = get_session() |
|||
langs = set(sm_ask_all_languages(session, url)) |
|||
tasks = sm_ask_all_tasks(session, url, langs) |
|||
drafts = sm_ask_all_drafts(session, url, langs) |
|||
all_tasks = [*tasks, *drafts] |
|||
# Map of task to (implemented in, not implemented in, omitted from) |
|||
counts: Dict[Task, Tuple[int, int, int]] = {} |
|||
# Running total of examples for all tasks. Where a language has multiple examples |
|||
# for a single tasks, we only count one example. |
|||
total: int = 0 |
|||
for task in all_tasks: |
|||
total += len(task.implemented_in) |
|||
counts[task] = ( |
|||
len(task.implemented_in), |
|||
len(task.not_implemented_in(langs)), |
|||
len(task.omitted_from), |
|||
) |
|||
# Pretty print |
|||
top = sorted(counts.items(), key=lambda it: it[1][0], reverse=True)[:n] |
|||
pad = max([len(task.fulltext) for task, _ in top]) |
|||
print("\nKnown languages:", len(langs)) |
|||
print("Total tasks:", len(all_tasks)) |
|||
print("Total examples:", total) |
|||
print(f"{'Task':>{pad}} | Implemented In | Not Implemented In | Omitted From") |
|||
print("-" * (pad + 1), "+", "-" * 16, "+", "-" * 20, "+", "-" * 13, sep="") |
|||
for task, _counts in top: |
|||
implemented_in, not_implemented_in, omitted_from = _counts |
|||
print( |
|||
f"{task.fulltext:>{pad}} |" |
|||
f"{implemented_in:>15} |" |
|||
f"{not_implemented_in:>19} |" |
|||
f"{omitted_from:>13}" |
|||
) |
|||
if __name__ == "__main__": |
|||
import argparse |
|||
URL = "https://rosettacode.org/w/api.php" |
|||
parser = argparse.ArgumentParser(description="Count tasks on Rosetta Code.") |
|||
parser.add_argument( |
|||
"--rows", |
|||
"-n", |
|||
type=int, |
|||
default=30, |
|||
dest="n", |
|||
help="number of rows to display in the output table (default: 30)", |
|||
) |
|||
parser.add_argument( |
|||
"--url", |
|||
default=URL, |
|||
help=f"target MediaWiki URL (default: {URL})", |
|||
) |
|||
args = parser.parse_args() |
|||
count_examples(args.url, args.n)</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
2023-02-11 11:09:34: ask [[Is language::+]] offset=0 |
|||
2023-02-11 11:09:35: ask [[Is language::+]] offset=500 |
|||
2023-02-11 11:09:36: ask [[Category:Programming Tasks]] offset=0 |
|||
2023-02-11 11:09:47: ask [[Category:Programming Tasks]] offset=500 |
|||
2023-02-11 11:10:04: ask [[Category:Programming Tasks]] offset=1000 |
|||
2023-02-11 11:10:12: ask [[Category:Draft Programming Tasks]] offset=0 |
|||
Known languages: 890 |
|||
Total tasks: 1602 |
|||
Total examples: 91075 |
|||
Task | Implemented In | Not Implemented In | Omitted From |
|||
--------------------------------+----------------+--------------------+------------- |
|||
Hello world/Text | 498 | 392 | 0 |
|||
99 bottles of beer | 371 | 519 | 0 |
|||
100 doors | 334 | 555 | 1 |
|||
FizzBuzz | 325 | 565 | 0 |
|||
Fibonacci sequence | 308 | 582 | 0 |
|||
Factorial | 302 | 588 | 0 |
|||
Comments | 297 | 592 | 1 |
|||
A+B | 293 | 597 | 0 |
|||
Empty program | 274 | 616 | 0 |
|||
Function definition | 254 | 634 | 2 |
|||
Loops/Infinite | 254 | 635 | 1 |
|||
Loops/For | 248 | 641 | 1 |
|||
Loops/While | 244 | 645 | 1 |
|||
Arrays | 237 | 652 | 1 |
|||
Ackermann function | 234 | 653 | 3 |
|||
Reverse a string | 231 | 657 | 2 |
|||
Conditional structures | 223 | 666 | 1 |
|||
Arithmetic/Integer | 213 | 677 | 0 |
|||
Greatest common divisor | 213 | 677 | 0 |
|||
Array concatenation | 208 | 682 | 0 |
|||
Greatest element of a list | 208 | 682 | 0 |
|||
Even or odd | 207 | 683 | 0 |
|||
Loops/Downward for | 207 | 683 | 0 |
|||
Sieve of Eratosthenes | 203 | 687 | 0 |
|||
Increment a numerical string | 202 | 688 | 0 |
|||
Integer comparison | 202 | 688 | 0 |
|||
Repeat a string | 199 | 691 | 0 |
|||
Boolean values | 198 | 691 | 1 |
|||
Loops/For with a specified step | 198 | 691 | 1 |
|||
Copy a string | 196 | 693 | 1 |
|||
</pre> |
|||
=={{header|R}}== |
=={{header|R}}== |
||
Line 6,195: | Line 2,716: | ||
{{libheader|RCurl}} |
{{libheader|RCurl}} |
||
<syntaxhighlight lang="r"> |
|||
<lang R> |
|||
library(XML) |
library(XML) |
||
library(RCurl) |
library(RCurl) |
||
Line 6,210: | Line 2,731: | ||
} |
} |
||
cat("Total: ", length(unlist(counts)), "examples\n") |
cat("Total: ", length(unlist(counts)), "examples\n") |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
< |
<syntaxhighlight lang="racket"> |
||
#lang racket |
#lang racket |
||
Line 6,240: | Line 2,761: | ||
(printf "~a: ~a\n" task s) |
(printf "~a: ~a\n" task s) |
||
s)) |
s)) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Raku}}== |
|||
(formerly Perl 6) |
|||
{{works with|Rakudo|2018.12}} |
|||
Retrieves counts for both Tasks and Draft Tasks. Save / Display results as a sortable wikitable rather than a static list. Click on a column header to sort on that column. To do a secondary sort, hold down the shift key and click on a second column header. Tasks have a gray (default) background, Draft Tasks have a yellow background. |
|||
This example tracks the top 50 languages by number of examples completed but only generates reports in tiers of 10. More than 10 gets too heavy and difficult to navigate. |
|||
Feed it parameters to control behaviour: |
|||
* :nf or :no-fetch to use saved information to generate the different reports. Recommended for the second, third, fourth, whatever report you are generating at any one time as fetching from the site is ''by far'' the most time consuming part. |
|||
* :t=1 (or :tier=1). :t=2, :t=3, whatever, up to :t=5 to control which tier of results to generate. |
|||
Language names with spaces will have underscores inserted to make the results uniform. Some oddball languages (lookin' at you Icon and Unicon) make it very difficult to obtain accurate results. The whole "conglomerate all of the Basic dialects together" movement of a few years ago also complicates things, but this should be pretty close. |
|||
For a full output, see [[Rosetta_Code/Count_examples/Full_list|Top tier]], [[Rosetta_Code/Count_examples/Full_list/Tier_2|Second tier]], [[Rosetta_Code/Count_examples/Full_list/Tier_3|Third tier]], [[Rosetta_Code/Count_examples/Full_list/Tier_4|Fourth tier]] |
|||
<syntaxhighlight lang="raku" line>use HTTP::UserAgent; |
|||
use URI::Escape; |
|||
use JSON::Fast; |
|||
use Lingua::EN::Numbers :short; |
|||
unit sub MAIN ( Bool :nf(:$no-fetch) = False, :t(:$tier) = 1 ); |
|||
# Friendlier descriptions for task categories |
|||
my %cat = ( |
|||
'Programming_Tasks' => 'Task', |
|||
'Draft_Programming_Tasks' => 'Draft' |
|||
); |
|||
my $client = HTTP::UserAgent.new; |
|||
$client.timeout = 10; |
|||
my $url = 'https://rosettacode.org/w'; |
|||
my $hashfile = './RC_Task_count.json'; |
|||
my $tablefile = "./RC_Task_count-{$tier}.txt"; |
|||
my %tasks; |
|||
my @places = <① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩ ⑪ ⑫ ⑬ ⑭ ⑮ ⑯ ⑰ ⑱ ⑲ ⑳ ㉑ ㉒ ㉓ ㉔ ㉕ |
|||
㉖ ㉗ ㉘ ㉙ ㉚ ㉛ ㉜ ㉝ ㉞ ㉟ ㊱ ㊲ ㊳ ㊴ ㊵ ㊶ ㊷ ㊸ ㊹ ㊺ ㊺ ㊻ ㊼ ㊽ ㊾ ㊿>; |
|||
# clear screen |
|||
run($*DISTRO.is-win ?? 'cls' !! 'clear') unless $no-fetch; |
|||
my %counts = |
|||
mediawiki-query( |
|||
$url, 'pages', |
|||
:generator<categorymembers>, |
|||
:gcmtitle<Category:Programming Languages>, |
|||
:gcmlimit<350>, |
|||
:rawcontinue(), |
|||
:prop<categoryinfo> |
|||
) |
|||
.map({ .<title>.subst(/^'Category:'/, '') => .<categoryinfo><pages> || 0 }); |
|||
my $per-tier = 10; |
|||
my $which = (^$per-tier) »+» $per-tier * ($tier - 1); |
|||
my @top-n = %counts.sort( {-.value, .key} )[|$which].map: *.key.trans(' ' => '_'); |
|||
# dump a copy to STDOUT, mostly for debugging purposes |
|||
say "<pre>{tc $tier.&ord-n} {$per-tier.&card} programming languages by number of task examples completed:"; |
|||
say ' ', join ' ', .map( {("{(@places[|$which])[$_]} {@top-n[$_]}").fmt("%-15s")} ) for (^@top-n).batch(5); |
|||
say "</pre>\n"; |
|||
unless $no-fetch { |
|||
note 'Retrieving task information...'; |
|||
mkdir('./pages') unless './pages'.IO.e; |
|||
@top-n = %counts.sort( {-.value, .key} )[^@places].map: *.key.trans(' ' => '_');; |
|||
for %cat.keys.sort -> $cat { |
|||
mediawiki-query( |
|||
$url, 'pages', |
|||
:generator<categorymembers>, |
|||
:gcmtitle("Category:$cat"), |
|||
:gcmlimit<350>, |
|||
:rawcontinue(), |
|||
:prop<title> |
|||
).map({ |
|||
my $page; |
|||
my $response; |
|||
loop { |
|||
$response = $client.get("{ $url }/index.php?title={ uri-escape .<title> }&action=raw"); |
|||
if $response.is-success { |
|||
$page = $response.content; |
|||
last; |
|||
} else { |
|||
redo; |
|||
} |
|||
} |
|||
"./pages/{ uri-escape .<title>.subst(/' '/, '_', :g) }".IO.spurt($page); |
|||
my $lc = $page.lc.trans(' ' => '_'); |
|||
my $count = +$lc.comb(/ ^^'==' <-[\n=]>* '{{header|' <-[}]>+? '}}==' \h* $$ /); |
|||
%tasks{.<title>} = {'cat' => %cat{$cat}, :$count}; |
|||
%tasks{.<title>}<top-n> = (^@top-n).map( { |
|||
($lc.contains("==\{\{header|{@top-n[$_].lc}}}") or |
|||
# Deal with 3 part headers - {{header|F_Sharp|F#}}, {{header|C_Sharp|C#}}, etc. |
|||
$lc.contains("==\{\{header|{@top-n[$_].lc}|") or |
|||
# Icon and Unicon are their own special flowers |
|||
$lc.contains("}}_and_\{\{header|{@top-n[$_].lc}}}==") or |
|||
# Language1 / Language2 for shared entries (e.g. C / C++) |
|||
$lc.contains(rx/'}}''_'*'/''_'*'{{header|'$(@top-n[$_].lc)'}}=='/)) ?? |
|||
(@places[$_]) !! |
|||
# Check if the task was omitted |
|||
$lc.contains("\{\{omit_from|{@top-n[$_].lc}") ?? 'O' !! |
|||
# The task is neither done or omitted |
|||
' ' |
|||
} ).join; |
|||
print clear, 1 + $++, ' ', %cat{$cat}, ' ', .<title>; |
|||
}) |
|||
} |
|||
print clear; |
|||
note "\nTask information saved to local file: {$hashfile.IO.absolute}"; |
|||
$hashfile.IO.spurt(%tasks.&to-json); |
|||
} |
|||
# Load information from local file |
|||
%tasks = $hashfile.IO.e ?? $hashfile.IO.slurp.&from-json !! ( ); |
|||
@top-n = %counts.sort( {-.value, .key} )[|$which].map: *.key.trans(' ' => '_'); |
|||
# Convert saved task info to a table |
|||
note "\nBuilding table..."; |
|||
my $count = +%tasks; |
|||
my $taskcnt = +%tasks.grep: *.value.<cat> eq %cat<Programming_Tasks>; |
|||
my $draftcnt = $count - $taskcnt; |
|||
my $total = sum %tasks{*}»<count>; |
|||
# Dump table to a file |
|||
my $out = open($tablefile, :w) or die "$!\n"; |
|||
$out.say: "<pre>{tc $tier.&ord-n} {$per-tier.&card} programming languages by number of task examples completed:"; |
|||
$out.say: ' ', join ' ', .map( {("{(@places[|$which])[$_]} {@top-n[$_]}").fmt("%-15s")} ) for (^@top-n).batch(5); |
|||
$out.say: "</pre>\n\n<div style=\"height:40em;overflow:scroll;\">"; |
|||
# Add table boilerplate and caption |
|||
$out.say: |
|||
'{|class="wikitable sortable"', "\n", |
|||
"|+ As of { DateTime.new(time) } :: Tasks: { $taskcnt } ::<span style=\"background-color:#ffd\"> Draft Tasks:", |
|||
"{ $draftcnt } </span>:: Total Tasks: { $count } :: Total Examples: { $total }\n", |
|||
"!Count!!Task!!{(@places[|$which]).join('!!')}" |
|||
; |
|||
# Sort tasks by count then add row |
|||
for %tasks.sort: { [-.value<count>, .key] } -> $task { |
|||
$out.say: |
|||
( $task.value<cat> eq 'Draft' |
|||
?? "|- style=\"background-color: #ffc\"\n" |
|||
!! "|-\n" |
|||
), |
|||
"| { $task.value<count> }\n", |
|||
( $task.key ~~ /\d/ |
|||
?? "|data-sort-value=\"{ $task.key.&naturally }\"| [[{uri-escape $task.key}|{$task.key}]]\n" |
|||
!! "| [[{uri-escape $task.key}|{$task.key}]]\n" |
|||
), |
|||
"|{ $task.value<top-n>.comb[|$which].join('||') }" |
|||
} |
|||
$out.say( "|}\n</div>" ); |
|||
$out.close; |
|||
note "Table file saved as: {$tablefile.IO.absolute}"; |
|||
sub mediawiki-query ($site, $type, *%query) { |
|||
my $url = "$site/api.php?" ~ uri-query-string( |
|||
:action<query>, :format<json>, :formatversion<2>, |%query); |
|||
my $continue = ''; |
|||
gather loop { |
|||
my $response = $client.get("$url&$continue"); |
|||
my $data = from-json($response.content); |
|||
take $_ for $data.<query>.{$type}.values; |
|||
$continue = uri-query-string |($data.<query-continue>{*}».hash.hash or last); |
|||
} |
|||
} |
|||
sub uri-query-string (*%fields) { %fields.map({ "{.key}={uri-escape .value}" }).join("&") } |
|||
sub naturally ($a) { $a.lc.subst(/(\d+)/, ->$/ {0~(65+$0.chars).chr~$0},:g) } |
|||
sub clear { "\r" ~ ' ' x 116 ~ "\r" }</syntaxhighlight> |
|||
{{out|Abridged output}} |
|||
<pre>Top ten programming language by number of task examples completed: |
|||
① Go |
|||
② Perl 6 |
|||
③ Kotlin |
|||
④ Python |
|||
⑤ Phix |
|||
⑥ Racket |
|||
⑦ Perl |
|||
⑧ C |
|||
⑨ Julia |
|||
⑩ Tcl |
|||
</pre> |
|||
<div style="height:40em;overflow:scroll;"> |
|||
{|class="wikitable sortable" |
|||
|+ As of 2019-01-21T22:41:28Z :: Tasks: 924 ::<span style="background-color:#ffd"> Draft Tasks:215 </span>:: Total Tasks: 1139 :: Total Examples: 59984 |
|||
!Count!!Task!!①!!②!!③!!④!!⑤!!⑥!!⑦!!⑧!!⑨!!⑩ |
|||
|- |
|||
| 405 |
|||
| [[Hello%20world%2FText|Hello world/Text]] |
|||
|①||②||③||④||⑤||⑥||⑦||⑧||⑨||⑩ |
|||
|- |
|||
| 283 |
|||
|data-sort-value="0C99 bottles of beer"| [[99%20Bottles%20of%20Beer|99 Bottles of Beer]] |
|||
|①||②||③||④||⑤||⑥||⑦||⑧||⑨||⑩ |
|||
|- |
|||
| 276 |
|||
| [[FizzBuzz|FizzBuzz]] |
|||
|①||②||③||④||⑤||⑥||⑦||⑧||⑨||⑩ |
|||
|- |
|||
| 273 |
|||
|data-sort-value="0D100 doors"| [[100%20doors|100 doors]] |
|||
|①||②||③||④||⑤||⑥||⑦||⑧||⑨||⑩ |
|||
|- |
|||
| 251 |
|||
| [[Fibonacci%20sequence|Fibonacci sequence]] |
|||
|①||②||③||④||⑤||⑥||⑦||⑧||⑨||⑩ |
|||
|- |
|||
| 246 |
|||
| [[Comments|Comments]] |
|||
|①||②||③||④||⑤||⑥||⑦||⑧||⑨||⑩ |
|||
|- |
|||
| 239 |
|||
| [[Factorial|Factorial]] |
|||
|①||②||③||④||⑤||⑥||⑦||⑧||⑨||⑩ |
|||
|- |
|||
| 223 |
|||
| [[Empty%20program|Empty program]] |
|||
|①||②||③||④||⑤||⑥||⑦||⑧||⑨||⑩ |
|||
|- |
|||
| 222 |
|||
| [[A%2BB|A+B]] |
|||
|①||②||③||④||⑤||⑥||⑦||⑧||⑨||⑩ |
|||
|- |
|||
| 214 |
|||
| [[Function%20definition|Function definition]] |
|||
|①||②||③||④||⑤||⑥||⑦||⑧||⑨||⑩ |
|||
|} |
|||
</div> |
|||
=={{header|Ring}}== |
|||
<syntaxhighlight lang="ring"> |
|||
# Project: Rosetta Code/Count examples |
|||
load "stdlib.ring" |
|||
ros= download("http://rosettacode.org/wiki/Category:Programming_Tasks") |
|||
pos = 1 |
|||
num = 0 |
|||
totalros = 0 |
|||
rosname = "" |
|||
rostitle = "" |
|||
for n = 1 to len(ros) |
|||
nr = searchstring(ros,'<li><a href="/wiki/',pos) |
|||
if nr = 0 |
|||
exit |
|||
else |
|||
pos = nr + 1 |
|||
ok |
|||
nr = searchname(nr) |
|||
nr = searchtitle(nr) |
|||
next |
|||
see nl |
|||
see "Total: " + totalros + " examples." + nl |
|||
func searchstring(str,substr,n) |
|||
newstr=right(str,len(str)-n+1) |
|||
nr = substr(newstr, substr) |
|||
if nr = 0 |
|||
return 0 |
|||
else |
|||
return n + nr -1 |
|||
ok |
|||
func searchname(sn) |
|||
nr2 = searchstring(ros,'">',sn) |
|||
nr3 = searchstring(ros,"</a></li>",sn) |
|||
rosname = substr(ros,nr2+2,nr3-nr2-2) |
|||
return sn |
|||
func searchtitle(sn) |
|||
st = searchstring(ros,"title=",sn) |
|||
rostitle = substr(ros,sn+19,st-sn-21) |
|||
rostitle = "rosettacode.org/wiki/" + rostitle |
|||
rostitle = download(rostitle) |
|||
sum = count(rostitle,"Edit section:") |
|||
num = num + 1 |
|||
see "" + num + ". " + rosname + ": " + sum + " examples." + nl |
|||
totalros = totalros + sum |
|||
return sn |
|||
func count(cstring,dstring) |
|||
sum = 0 |
|||
while substr(cstring,dstring) > 0 |
|||
sum = sum + 1 |
|||
cstring = substr(cstring,substr(cstring,dstring)+len(string(sum))) |
|||
end |
|||
return sum |
|||
</syntaxhighlight> |
|||
Output: |
|||
<pre> |
|||
1. 100 doors: 331 examples. |
|||
2. 15 Puzzle Game: 48 examples. |
|||
3. 15 puzzle solver: 18 examples. |
|||
4. 2048: 40 examples. |
|||
5. 24 game: 95 examples. |
|||
6. 24 game/Solve: 59 examples. |
|||
7. 4-rings or 4-squares puzzle: 42 examples. |
|||
8. 9 billion names of God the integer: 54 examples. |
|||
9. 99 Bottles of Beer: 393 examples. |
|||
10. A+B: 250 examples. |
|||
...... |
|||
872. XML/XPath: 54 examples. |
|||
873. Y combinator: 88 examples. |
|||
874. Yahoo! search interface: 20 examples. |
|||
875. Yin and yang: 59 examples. |
|||
876. Zebra puzzle: 58 examples. |
|||
877. Zeckendorf arithmetic: 11 examples. |
|||
878. Zeckendorf number representation: 64 examples. |
|||
879. Zero to the zero power: 100 examples. |
|||
880. Zhang-Suen thinning algorithm: 26 examples. |
|||
881. Zig-zag matrix: 112 examples. |
|||
Total: 62677 examples. |
|||
</pre> |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
{{libheader|REXML}} |
{{libheader|REXML}} |
||
First, a RosettaCode module, saved as <tt>rosettacode.rb</tt>: |
First, a RosettaCode module, saved as <tt>rosettacode.rb</tt>: |
||
< |
<syntaxhighlight lang="ruby">require 'open-uri' |
||
require 'rexml/document' |
require 'rexml/document' |
||
Line 6,295: | Line 3,152: | ||
end |
end |
||
end</ |
end</syntaxhighlight> |
||
Then, we implement the task with: |
Then, we implement the task with: |
||
< |
<syntaxhighlight lang="ruby">require 'rosettacode' |
||
total_examples = 0 |
total_examples = 0 |
||
Line 6,310: | Line 3,167: | ||
puts |
puts |
||
puts "Total: #{total_examples}"</ |
puts "Total: #{total_examples}"</syntaxhighlight> |
||
=={{header|Run BASIC}}== |
|||
<syntaxhighlight lang="runbasic">html "<table border=1><tr bgcolor=wheat align=center><td>Num</td><td>Task</td><td>Examples</td></tr>" |
|||
a$ = httpGet$("http://rosettacode.org/wiki/Category:Programming_Tasks") |
|||
a$ = word$(a$,1,"</table></div>") |
|||
i = instr(a$,"<a href=""/wiki/") |
|||
i = instr(a$,"<a href=""/wiki/",i+1) |
|||
while i > 0 |
|||
count = count + 1 |
|||
i = instr(a$,"<a href=""/wiki/",i+1) |
|||
j = instr(a$,">",i+5) |
|||
a1$ = mid$(a$,i+15,j-i) |
|||
taskId$ = word$(a1$,1,"""") |
|||
task$ = word$(a1$,3,"""") |
|||
url$ = "http://rosettacode.org/wiki/";taskId$ |
|||
a2$ = httpGet$(url$) |
|||
ii = instr(a2$,"<span class=""tocnumber"">") |
|||
jj = 0 |
|||
while ii > 0 |
|||
jj = ii |
|||
ii = instr(a2$,"<span class=""tocnumber"">",ii+10) |
|||
wend |
|||
if jj = 0 then |
|||
examp = 0 |
|||
else |
|||
kk = instr(a2$,"<",jj+24) |
|||
examp = int(val(mid$(a2$,jj+24,kk-jj-24))) |
|||
end if |
|||
html "<tr><td align=right>";count;"</td><td>";task$;"</td><td align=right>";examp;"</td></tr>" |
|||
totExamp = totExamp + examp |
|||
wend |
|||
html "<tr bgcolor=wheat><td>**</td><td>** Total **</td><td align=right>";totExamp;"</td></tr></table>" |
|||
end</syntaxhighlight> |
|||
<table border=1><tr bgcolor=wheat align=center><td>Num</td><td>Task</td><td>Examples</td></tr> |
|||
<tr><td align=right>1</td><td>100 doors</td><td align=right>165</td></tr> |
|||
<tr><td align=right>2</td><td>24 game</td><td align=right>56</td></tr> |
|||
<tr><td align=right>3</td><td>24 game/Solve</td><td align=right>34</td></tr> |
|||
<tr><td align=right>4</td><td>99 Bottles of Beer</td><td align=right>192</td></tr> |
|||
<tr><td align=right>5</td><td>A+B</td><td align=right>129</td></tr> |
|||
<tr><td align=right>6</td><td>Abstract type</td><td align=right>51</td></tr> |
|||
<tr><td align=right>7</td><td>Accumulator factory</td><td align=right>65</td></tr> |
|||
<tr><td align=right>8</td><td>Ackermann function</td><td align=right>132</td></tr> |
|||
<tr><td align=right>9</td><td>Active Directory/Connect</td><td align=right>13</td></tr> |
|||
<tr><td align=right>10</td><td>Active Directory/Search for a user</td><td align=right>13</td></tr> |
|||
<tr><td align=right>11</td><td>Active object</td><td align=right>22</td></tr> |
|||
<tr><td align=right>12</td><td>Add a variable to a class instance at runtime</td><td align=right>37</td></tr> |
|||
<tr><td align=right>...</td><td>...</td><td align=right>...</td></tr> |
|||
<tr><td align=right>655</td><td>Y combinator</td><td align=right>53</td></tr> |
|||
<tr><td align=right>656</td><td>Yahoo! search interface</td><td align=right>16</td></tr> |
|||
<tr><td align=right>657</td><td>Yin and yang</td><td align=right>38</td></tr> |
|||
<tr><td align=right>658</td><td>Zebra puzzle</td><td align=right>12</td></tr> |
|||
<tr><td align=right>659</td><td>Zeckendorf number representation</td><td align=right>18</td></tr> |
|||
<tr><td align=right>660</td><td>Zig-zag matrix</td><td align=right>65</td></tr> |
|||
<tr bgcolor=wheat><td>**</td><td>** Total **</td><td align=right>28611</td></tr></table> |
|||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
< |
<syntaxhighlight lang="rust">extern crate reqwest; |
||
extern crate url; |
extern crate url; |
||
extern crate rustc_serialize; |
extern crate rustc_serialize; |
||
Line 6,424: | Line 3,336: | ||
let json: Json = query_api(query).unwrap(); |
let json: Json = query_api(query).unwrap(); |
||
count_number_examples(&json, task.page_id).unwrap() |
count_number_examples(&json, task.page_id).unwrap() |
||
}</ |
}</syntaxhighlight> |
||
The function is then run using the following: |
The function is then run using the following: |
||
< |
<syntaxhighlight lang="rust"> |
||
extern crate count_examples; |
extern crate count_examples; |
||
fn main() { |
fn main() { |
||
Line 6,435: | Line 3,347: | ||
println!("Task: {} has {} examples", task.title, count); |
println!("Task: {} has {} examples", task.title, count); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Run BASIC}}== |
|||
<lang runbasic>html "<table border=1><tr bgcolor=wheat align=center><td>Num</td><td>Task</td><td>Examples</td></tr>" |
|||
a$ = httpGet$("http://rosettacode.org/wiki/Category:Programming_Tasks") |
|||
a$ = word$(a$,1,"</table></div>") |
|||
i = instr(a$,"<a href=""/wiki/") |
|||
i = instr(a$,"<a href=""/wiki/",i+1) |
|||
while i > 0 |
|||
count = count + 1 |
|||
i = instr(a$,"<a href=""/wiki/",i+1) |
|||
j = instr(a$,">",i+5) |
|||
a1$ = mid$(a$,i+15,j-i) |
|||
taskId$ = word$(a1$,1,"""") |
|||
task$ = word$(a1$,3,"""") |
|||
url$ = "http://rosettacode.org/wiki/";taskId$ |
|||
a2$ = httpGet$(url$) |
|||
ii = instr(a2$,"<span class=""tocnumber"">") |
|||
jj = 0 |
|||
while ii > 0 |
|||
jj = ii |
|||
ii = instr(a2$,"<span class=""tocnumber"">",ii+10) |
|||
wend |
|||
if jj = 0 then |
|||
examp = 0 |
|||
else |
|||
kk = instr(a2$,"<",jj+24) |
|||
examp = int(val(mid$(a2$,jj+24,kk-jj-24))) |
|||
end if |
|||
html "<tr><td align=right>";count;"</td><td>";task$;"</td><td align=right>";examp;"</td></tr>" |
|||
totExamp = totExamp + examp |
|||
wend |
|||
html "<tr bgcolor=wheat><td>**</td><td>** Total **</td><td align=right>";totExamp;"</td></tr></table>" |
|||
end</lang> |
|||
<table border=1><tr bgcolor=wheat align=center><td>Num</td><td>Task</td><td>Examples</td></tr> |
|||
<tr><td align=right>1</td><td>100 doors</td><td align=right>165</td></tr> |
|||
<tr><td align=right>2</td><td>24 game</td><td align=right>56</td></tr> |
|||
<tr><td align=right>3</td><td>24 game/Solve</td><td align=right>34</td></tr> |
|||
<tr><td align=right>4</td><td>99 Bottles of Beer</td><td align=right>192</td></tr> |
|||
<tr><td align=right>5</td><td>A+B</td><td align=right>129</td></tr> |
|||
<tr><td align=right>6</td><td>Abstract type</td><td align=right>51</td></tr> |
|||
<tr><td align=right>7</td><td>Accumulator factory</td><td align=right>65</td></tr> |
|||
<tr><td align=right>8</td><td>Ackermann function</td><td align=right>132</td></tr> |
|||
<tr><td align=right>9</td><td>Active Directory/Connect</td><td align=right>13</td></tr> |
|||
<tr><td align=right>10</td><td>Active Directory/Search for a user</td><td align=right>13</td></tr> |
|||
<tr><td align=right>11</td><td>Active object</td><td align=right>22</td></tr> |
|||
<tr><td align=right>12</td><td>Add a variable to a class instance at runtime</td><td align=right>37</td></tr> |
|||
<tr><td align=right>...</td><td>...</td><td align=right>...</td></tr> |
|||
<tr><td align=right>655</td><td>Y combinator</td><td align=right>53</td></tr> |
|||
<tr><td align=right>656</td><td>Yahoo! search interface</td><td align=right>16</td></tr> |
|||
<tr><td align=right>657</td><td>Yin and yang</td><td align=right>38</td></tr> |
|||
<tr><td align=right>658</td><td>Zebra puzzle</td><td align=right>12</td></tr> |
|||
<tr><td align=right>659</td><td>Zeckendorf number representation</td><td align=right>18</td></tr> |
|||
<tr><td align=right>660</td><td>Zig-zag matrix</td><td align=right>65</td></tr> |
|||
<tr bgcolor=wheat><td>**</td><td>** Total **</td><td align=right>28611</td></tr></table> |
|||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
{{libheader|Scala}}< |
{{libheader|Scala}}<syntaxhighlight lang="scala">import scala.language.postfixOps |
||
object TaskCount extends App { |
object TaskCount extends App { |
||
Line 6,517: | Line 3,374: | ||
counts map (_.apply) map Function.tupled("%s: %d examples." format (_, _)) foreach println |
counts map (_.apply) map Function.tupled("%s: %d examples." format (_, _)) foreach println |
||
println("\nTotal: %d examples." format (counts map (_.apply._2) sum)) |
println("\nTotal: %d examples." format (counts map (_.apply._2) sum)) |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
{{trans|Perl}} |
{{trans|Perl}} |
||
< |
<syntaxhighlight lang="ruby">var lwp = require('LWP::UserAgent').new(agent => 'Mozilla/5.0'); |
||
var site = 'http://rosettacode.org'; |
var site = 'http://rosettacode.org'; |
||
Line 6,533: | Line 3,390: | ||
var count = lwp.get("#{site}/wiki/#{slug}").decoded_content.count(/toclevel-1/g); |
var count = lwp.get("#{site}/wiki/#{slug}").decoded_content.count(/toclevel-1/g); |
||
say "#{m[0]}: #{count} examples"; |
say "#{m[0]}: #{count} examples"; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
100 doors: |
100 doors: 278 examples |
||
15 Puzzle Game: 50 examples |
|||
15 puzzle solver: 10 examples |
|||
2048: 41 examples |
|||
24 game: 91 examples |
|||
24 game/Solve: 56 examples |
|||
4-rings or 4-squares puzzle: 44 examples |
|||
9 billion names of God the integer: 48 examples |
|||
99 Bottles of Beer: 287 examples |
|||
A+B: 228 examples |
|||
... |
... |
||
</pre> |
</pre> |
||
Line 6,549: | Line 3,408: | ||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
{{tcllib|json}} |
{{tcllib|json}} |
||
< |
<syntaxhighlight lang="tcl">package require Tcl 8.5 |
||
package require http |
package require http |
||
package require json |
package require json |
||
Line 6,613: | Line 3,472: | ||
} |
} |
||
puts "\nTotal: $total examples"</ |
puts "\nTotal: $total examples"</syntaxhighlight> |
||
=={{header|TUSCRIPT}}== |
=={{header|TUSCRIPT}}== |
||
< |
<syntaxhighlight lang="tuscript">$$ MODE TUSCRIPT |
||
url="http://www.rosettacode.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml" |
url="http://www.rosettacode.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml" |
||
data=REQUEST (url) |
data=REQUEST (url) |
||
Line 6,655: | Line 3,514: | ||
FILE "tasks" = line |
FILE "tasks" = line |
||
</syntaxhighlight> |
|||
</lang> |
|||
Output in file "tasks": |
Output in file "tasks": |
||
<pre style='height:30ex;overflow:scroll'> |
<pre style='height:30ex;overflow:scroll'> |
||
Line 6,674: | Line 3,533: | ||
Zig-zag matrix=46 members |
Zig-zag matrix=46 members |
||
2011-01-15 03:41:30: 455 Programing Tasks: 16009 solutions |
2011-01-15 03:41:30: 455 Programing Tasks: 16009 solutions |
||
</pre> |
|||
=={{header|UNIX Shell}}== |
|||
{{works with|Bourne Again Shell}} |
|||
{{trans|Python}} |
|||
Requires the <tt>curl</tt> and <tt>jq</tt> command-line utilities. |
|||
<syntaxhighlight lang="sh">#!/usr/bin/env bash |
|||
SITE=https://www.rosettacode.org |
|||
API=$SITE/mw/api.php |
|||
PAGES=$SITE/mw/index.php |
|||
query="$API?action=query" |
|||
query+=$(printf '&%s' \ |
|||
list=categorymembers \ |
|||
cmtitle=Category:Programming_Tasks \ |
|||
cmlimit=500) |
|||
total=0 |
|||
while read title; do |
|||
t=${title// /_} |
|||
tasks=$(curl -s "$PAGES?title=$t&action=raw" \ |
|||
| grep -c '{{header|') |
|||
printf '%s: %d examples.\n' "$title" "$tasks" |
|||
let total+=tasks |
|||
done < <(curl -s "$query&format=json" \ |
|||
| jq -r '.query.categorymembers[].title') |
|||
printf '\nTotal: %d examples.\n' "$total"</syntaxhighlight> |
|||
=={{header|Wren}}== |
|||
{{libheader|libcurl}} |
|||
{{libheader|Wren-pattern}} |
|||
An embedded program so we can use the libcurl library. |
|||
<syntaxhighlight lang="wren">/* Rosetta_Code_Count_examples.wren */ |
|||
import "./pattern" for Pattern |
|||
var CURLOPT_URL = 10002 |
|||
var CURLOPT_FOLLOWLOCATION = 52 |
|||
var CURLOPT_WRITEFUNCTION = 20011 |
|||
var CURLOPT_WRITEDATA = 10001 |
|||
foreign class Buffer { |
|||
construct new() {} // C will allocate buffer of a suitable size |
|||
foreign value // returns buffer contents as a string |
|||
} |
|||
foreign class Curl { |
|||
construct easyInit() {} |
|||
foreign easySetOpt(opt, param) |
|||
foreign easyPerform() |
|||
foreign easyCleanup() |
|||
} |
|||
var curl = Curl.easyInit() |
|||
var getContent = Fn.new { |url| |
|||
var buffer = Buffer.new() |
|||
curl.easySetOpt(CURLOPT_URL, url) |
|||
curl.easySetOpt(CURLOPT_FOLLOWLOCATION, 1) |
|||
curl.easySetOpt(CURLOPT_WRITEFUNCTION, 0) // write function to be supplied by C |
|||
curl.easySetOpt(CURLOPT_WRITEDATA, buffer) |
|||
curl.easyPerform() |
|||
return buffer.value |
|||
} |
|||
var url = "https://www.rosettacode.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml" |
|||
var content = getContent.call(url) |
|||
var p = Pattern.new("title/=\"[+1^\"]\"") |
|||
var matches = p.findAll(content) |
|||
for (m in matches) { |
|||
var title = m.capsText[0].replace("'", "'").replace(""", "\"") |
|||
var title2 = title.replace(" ", "_").replace("+", "\%252B") |
|||
var taskUrl = "https://www.rosettacode.org/w/index.php?title=%(title2)&action=raw" |
|||
var taskContent = getContent.call(taskUrl) |
|||
var lines = taskContent.split("\n") |
|||
var count = lines.count { |line| line.trim().startsWith("=={{header|") } |
|||
System.print("%(title) : %(count) examples") |
|||
} |
|||
curl.easyCleanup()</syntaxhighlight> |
|||
<br> |
|||
which we now embed in the following C program, build and run. |
|||
<syntaxhighlight lang="c">/* gcc Rosetta_Code_Count_examples.c -o Rosetta_Code_Count_examples -lcurl -lwren -lm */ |
|||
#include <stdio.h> |
|||
#include <stdlib.h> |
|||
#include <string.h> |
|||
#include <curl/curl.h> |
|||
#include "wren.h" |
|||
struct MemoryStruct { |
|||
char *memory; |
|||
size_t size; |
|||
}; |
|||
/* C <=> Wren interface functions */ |
|||
static size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp) { |
|||
size_t realsize = size * nmemb; |
|||
struct MemoryStruct *mem = (struct MemoryStruct *)userp; |
|||
char *ptr = realloc(mem->memory, mem->size + realsize + 1); |
|||
if(!ptr) { |
|||
/* out of memory! */ |
|||
printf("not enough memory (realloc returned NULL)\n"); |
|||
return 0; |
|||
} |
|||
mem->memory = ptr; |
|||
memcpy(&(mem->memory[mem->size]), contents, realsize); |
|||
mem->size += realsize; |
|||
mem->memory[mem->size] = 0; |
|||
return realsize; |
|||
} |
|||
void C_bufferAllocate(WrenVM* vm) { |
|||
struct MemoryStruct *ms = (struct MemoryStruct *)wrenSetSlotNewForeign(vm, 0, 0, sizeof(struct MemoryStruct)); |
|||
ms->memory = malloc(1); |
|||
ms->size = 0; |
|||
} |
|||
void C_bufferFinalize(void* data) { |
|||
struct MemoryStruct *ms = (struct MemoryStruct *)data; |
|||
free(ms->memory); |
|||
} |
|||
void C_curlAllocate(WrenVM* vm) { |
|||
CURL** pcurl = (CURL**)wrenSetSlotNewForeign(vm, 0, 0, sizeof(CURL*)); |
|||
*pcurl = curl_easy_init(); |
|||
} |
|||
void C_value(WrenVM* vm) { |
|||
struct MemoryStruct *ms = (struct MemoryStruct *)wrenGetSlotForeign(vm, 0); |
|||
wrenSetSlotString(vm, 0, ms->memory); |
|||
} |
|||
void C_easyPerform(WrenVM* vm) { |
|||
CURL* curl = *(CURL**)wrenGetSlotForeign(vm, 0); |
|||
curl_easy_perform(curl); |
|||
} |
|||
void C_easyCleanup(WrenVM* vm) { |
|||
CURL* curl = *(CURL**)wrenGetSlotForeign(vm, 0); |
|||
curl_easy_cleanup(curl); |
|||
} |
|||
void C_easySetOpt(WrenVM* vm) { |
|||
CURL* curl = *(CURL**)wrenGetSlotForeign(vm, 0); |
|||
CURLoption opt = (CURLoption)wrenGetSlotDouble(vm, 1); |
|||
if (opt < 10000) { |
|||
long lparam = (long)wrenGetSlotDouble(vm, 2); |
|||
curl_easy_setopt(curl, opt, lparam); |
|||
} else if (opt < 20000) { |
|||
if (opt == CURLOPT_WRITEDATA) { |
|||
struct MemoryStruct *ms = (struct MemoryStruct *)wrenGetSlotForeign(vm, 2); |
|||
curl_easy_setopt(curl, opt, (void *)ms); |
|||
} else if (opt == CURLOPT_URL) { |
|||
const char *url = wrenGetSlotString(vm, 2); |
|||
curl_easy_setopt(curl, opt, url); |
|||
} |
|||
} else if (opt < 30000) { |
|||
if (opt == CURLOPT_WRITEFUNCTION) { |
|||
curl_easy_setopt(curl, opt, &WriteMemoryCallback); |
|||
} |
|||
} |
|||
} |
|||
WrenForeignClassMethods bindForeignClass(WrenVM* vm, const char* module, const char* className) { |
|||
WrenForeignClassMethods methods; |
|||
methods.allocate = NULL; |
|||
methods.finalize = NULL; |
|||
if (strcmp(module, "main") == 0) { |
|||
if (strcmp(className, "Buffer") == 0) { |
|||
methods.allocate = C_bufferAllocate; |
|||
methods.finalize = C_bufferFinalize; |
|||
} else if (strcmp(className, "Curl") == 0) { |
|||
methods.allocate = C_curlAllocate; |
|||
} |
|||
} |
|||
return methods; |
|||
} |
|||
WrenForeignMethodFn bindForeignMethod( |
|||
WrenVM* vm, |
|||
const char* module, |
|||
const char* className, |
|||
bool isStatic, |
|||
const char* signature) { |
|||
if (strcmp(module, "main") == 0) { |
|||
if (strcmp(className, "Buffer") == 0) { |
|||
if (!isStatic && strcmp(signature, "value") == 0) return C_value; |
|||
} else if (strcmp(className, "Curl") == 0) { |
|||
if (!isStatic && strcmp(signature, "easySetOpt(_,_)") == 0) return C_easySetOpt; |
|||
if (!isStatic && strcmp(signature, "easyPerform()") == 0) return C_easyPerform; |
|||
if (!isStatic && strcmp(signature, "easyCleanup()") == 0) return C_easyCleanup; |
|||
} |
|||
} |
|||
return NULL; |
|||
} |
|||
static void writeFn(WrenVM* vm, const char* text) { |
|||
printf("%s", text); |
|||
} |
|||
void errorFn(WrenVM* vm, WrenErrorType errorType, const char* module, const int line, const char* msg) { |
|||
switch (errorType) { |
|||
case WREN_ERROR_COMPILE: |
|||
printf("[%s line %d] [Error] %s\n", module, line, msg); |
|||
break; |
|||
case WREN_ERROR_STACK_TRACE: |
|||
printf("[%s line %d] in %s\n", module, line, msg); |
|||
break; |
|||
case WREN_ERROR_RUNTIME: |
|||
printf("[Runtime Error] %s\n", msg); |
|||
break; |
|||
} |
|||
} |
|||
char *readFile(const char *fileName) { |
|||
FILE *f = fopen(fileName, "r"); |
|||
fseek(f, 0, SEEK_END); |
|||
long fsize = ftell(f); |
|||
rewind(f); |
|||
char *script = malloc(fsize + 1); |
|||
fread(script, 1, fsize, f); |
|||
fclose(f); |
|||
script[fsize] = 0; |
|||
return script; |
|||
} |
|||
static void loadModuleComplete(WrenVM* vm, const char* module, WrenLoadModuleResult result) { |
|||
if( result.source) free((void*)result.source); |
|||
} |
|||
WrenLoadModuleResult loadModule(WrenVM* vm, const char* name) { |
|||
WrenLoadModuleResult result = {0}; |
|||
if (strcmp(name, "random") != 0 && strcmp(name, "meta") != 0) { |
|||
result.onComplete = loadModuleComplete; |
|||
char fullName[strlen(name) + 6]; |
|||
strcpy(fullName, name); |
|||
strcat(fullName, ".wren"); |
|||
result.source = readFile(fullName); |
|||
} |
|||
return result; |
|||
} |
|||
int main(int argc, char **argv) { |
|||
WrenConfiguration config; |
|||
wrenInitConfiguration(&config); |
|||
config.writeFn = &writeFn; |
|||
config.errorFn = &errorFn; |
|||
config.bindForeignClassFn = &bindForeignClass; |
|||
config.bindForeignMethodFn = &bindForeignMethod; |
|||
config.loadModuleFn = &loadModule; |
|||
WrenVM* vm = wrenNewVM(&config); |
|||
const char* module = "main"; |
|||
const char* fileName = "Rosetta_Code_Count_examples.wren"; |
|||
char *script = readFile(fileName); |
|||
WrenInterpretResult result = wrenInterpret(vm, module, script); |
|||
switch (result) { |
|||
case WREN_RESULT_COMPILE_ERROR: |
|||
printf("Compile Error!\n"); |
|||
break; |
|||
case WREN_RESULT_RUNTIME_ERROR: |
|||
printf("Runtime Error!\n"); |
|||
break; |
|||
case WREN_RESULT_SUCCESS: |
|||
break; |
|||
} |
|||
wrenFreeVM(vm); |
|||
free(script); |
|||
return 0; |
|||
}</syntaxhighlight> |
|||
{{out}} |
|||
Just showing the first 25 'full' tasks: |
|||
<pre> |
|||
100 doors : 355 examples |
|||
100 prisoners : 85 examples |
|||
15 puzzle game : 86 examples |
|||
15 puzzle solver : 27 examples |
|||
2048 : 65 examples |
|||
21 game : 52 examples |
|||
24 game : 107 examples |
|||
24 game/Solve : 64 examples |
|||
4-rings or 4-squares puzzle : 74 examples |
|||
9 billion names of God the integer : 66 examples |
|||
99 bottles of beer : 376 examples |
|||
A+B : 296 examples |
|||
Abbreviations, automatic : 58 examples |
|||
Abbreviations, easy : 50 examples |
|||
Abbreviations, simple : 46 examples |
|||
ABC problem : 150 examples |
|||
Abelian sandpile model : 40 examples |
|||
Abelian sandpile model/Identity : 28 examples |
|||
Abstract type : 93 examples |
|||
Abundant odd numbers : 72 examples |
|||
Abundant, deficient and perfect number classifications : 110 examples |
|||
Accumulator factory : 115 examples |
|||
Achilles numbers : 25 examples |
|||
Ackermann function : 243 examples |
|||
Active Directory/Connect : 29 examples |
|||
.... |
|||
</pre> |
</pre> |
||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
Uses shared libraries YAJL and cURL and handles "continue" responses. |
Uses shared libraries YAJL and cURL and handles "continue" responses. |
||
< |
<syntaxhighlight lang="zkl">var [const] YAJL=Import("zklYAJL")[0], CURL=Import("zklCurl"); |
||
fcn getTasks(language){ |
fcn getTasks(language){ |
||
Line 6,697: | Line 3,863: | ||
tasks |
tasks |
||
} |
} |
||
re:=RegExp(0'!\s+==\s*{{\s*header\s*|!); // == {{ header | zkl |
re:=RegExp(0'!\s+==\s*{{\s*header\s*\|!); // == {{ header | zkl |
||
foreach task in (getTasks("Programming_Tasks")){ |
foreach task in (getTasks("Programming_Tasks")){ |
||
page:=CURL().get( |
page:=CURL().get( |
||
Line 6,705: | Line 3,871: | ||
cnt,n:=0,0; while(re.search(page,True,n)){ cnt+=1; n=re.matched[0].sum(0); } |
cnt,n:=0,0; while(re.search(page,True,n)){ cnt+=1; n=re.matched[0].sum(0); } |
||
"%4d: %s".fmt(cnt,task).println(); |
"%4d: %s".fmt(cnt,task).println(); |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
Revision as of 11:35, 3 February 2024
You are encouraged to solve this task according to the task description, using any language you may know.
Find the total number of programming examples for each task and the total for all tasks.
Essentially, count the number of occurrences of =={{header| on each task page.
Output:
100 doors: 20 examples. 99 Bottles of Beer: 29 examples. Abstract type: 10 examples. Total: X examples.
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
Ada
Parsing XML file with XMLAda from AdaCore
with Aws.Client, Aws.Messages, Aws.Response, Aws.Resources, Aws.Url;
with Dom.Readers, Dom.Core, Dom.Core.Documents, Dom.Core.Nodes, Dom.Core.Attrs;
with Input_Sources.Strings, Unicode, Unicode.Ces.Utf8;
with Ada.Strings.Unbounded, Ada.Strings.Fixed, Ada.Text_IO, Ada.Command_Line;
with Ada.Containers.Vectors;
use Aws.Client, Aws.Messages, Aws.Response, Aws.Resources, Aws.Url;
use Dom.Readers, Dom.Core, Dom.Core.Documents, Dom.Core.Nodes, Dom.Core.Attrs;
use Aws, Ada.Strings.Unbounded, Ada.Strings.Fixed, Input_Sources.Strings;
use Ada.Text_IO, Ada.Command_Line;
procedure Count_Examples is
package Members_Vectors is new Ada.Containers.Vectors (
Index_Type => Positive,
Element_Type => Unbounded_String);
use Members_Vectors;
Exemples : Vector;
Nbr_Lg, Total : Natural := 0;
procedure Get_Vector (Category : in String; Mbr_Vector : in out Vector) is
Reader : Tree_Reader;
Doc : Document;
List : Node_List;
N : Node;
A : Attr;
Page : Aws.Response.Data;
Uri_Xml : constant String :=
"http://rosettacode.org/mw/api.php?action=query&list=categorymembers"
&
"&format=xml&cmlimit=500&cmtitle=Category:";
begin
Page := Client.Get (Uri_Xml & Category);
if Response.Status_Code (Page) not in Messages.Success then
raise Client.Connection_Error;
end if;
declare
Xml : constant String := Message_Body (Page);
Source : String_Input;
begin
Open
(Xml'Unrestricted_Access,
Unicode.Ces.Utf8.Utf8_Encoding,
Source);
Parse (Reader, Source);
Close (Source);
end;
Doc := Get_Tree (Reader);
List := Get_Elements_By_Tag_Name (Doc, "cm");
for Index in 1 .. Length (List) loop
N := Item (List, Index - 1);
A := Get_Named_Item (Attributes (N), "title");
Append (Mbr_Vector, To_Unbounded_String (Value (A)));
end loop;
Free (List);
Free (Reader);
end Get_Vector;
function Scan_Page (Title : String) return Natural is
Page : Aws.Response.Data;
File : Aws.Resources.File_Type;
Buffer : String (1 .. 1024);
Languages, Position, Last : Natural := 0;
begin
Page :=
Client.Get
("http://rosettacode.org/mw/index.php?title=" &
Aws.Url.Encode (Title) &
"&action=raw");
Response.Message_Body (Page, File);
while not End_Of_File (File) loop
Resources.Get_Line (File, Buffer, Last);
Position :=
Index
(Source => Buffer (Buffer'First .. Last),
Pattern => "=={{header|");
if Position > 0 then
Languages := Languages + 1;
end if;
end loop;
Close (File);
return Languages;
end Scan_Page;
begin
Get_Vector ("Programming_Tasks", Exemples);
for I in First_Index (Exemples) .. Last_Index (Exemples) loop
declare
Title : constant String :=
To_String (Members_Vectors.Element (Exemples, I));
begin
Nbr_Lg := Scan_Page (Title);
Total := Total + Nbr_Lg;
Put_Line (Title & " :" & Integer'Image (Nbr_Lg) & " exemples.");
end;
end loop;
Put_Line ("Total :" & Integer'Image (Total) & " exemples.");
end Count_Examples;
Output :
100 doors : 107 exemples. 24 game : 30 exemples. .... Yahoo! search interface : 10 exemples. Zig-zag matrix : 49 exemples. Total : 17238 exemples.
AutoHotkey
UrlDownloadToFile
, http://www.rosettacode.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml
, tasks.xml
FileRead, tasks, tasks.xml
pos = 0
quote = " ; "
regtitle := "<cm.*?title=" . quote . "(.*?)" . quote
While, pos := RegExMatch(tasks, regtitle, title, pos + 1)
{
UrlDownloadToFile
, % "http://www.rosettacode.org/w/index.php?title=" . title1 . "&action=raw"
, task.xml
FileRead, task, task.xml
RegExReplace(task, "\{\{header\|", "", count)
current := title1 . ": " . count . " examples.`n"
output .= current
TrayTip, current, % current
}
MsgBox % output
Return
BBC BASIC
VDU 23,22,640;512;8,16,16,128+8 : REM Enable UTF-8 support
SYS "LoadLibrary", "URLMON.DLL" TO urlmon%
SYS "GetProcAddress", urlmon%, "URLDownloadToFileA" TO UDTF
special$ = "+()'"
url$ = "http://www.rosettacode.org/w/api.php?action=query" + \
\ "&list=categorymembers&cmtitle=Category:Programming_Tasks" + \
\ "&cmlimit=500&format=xml"
file$ = @tmp$ + "tasks.xml"
SYS UDTF, 0, url$, file$, 0, 0 TO fail%
IF fail% ERROR 100, "File download failed (tasks)"
Total% = 0
file% = OPENIN(file$)
WHILE NOT EOF#file%
a$ = GET$#file%
i% = 0
REPEAT
i% = INSTR(a$, "title=", i%+1)
IF i% THEN
j% = INSTR(a$, ">", i%)
title$ = MID$(a$, i%+7, j%-i%-10)
REM Replace HTML codes:
REPEAT
k% = INSTR(title$, "&")
IF k% THEN
l% = INSTR(title$, ";", k%)
title$ = LEFT$(title$,k%-1) + \
\ FNhtml(MID$(title$,k%,l%-k%+1)) + MID$(title$,l%+1)
ENDIF
UNTIL k% = 0
t$ = title$
REM Substitute characters not allowed in a URL:
FOR s% = 1 TO LEN(special$)
REPEAT
s$ = MID$(special$, s%, 1)
k% = INSTR(t$, s$)
IF k% t$ = LEFT$(t$,k%-1) + "%" + STR$~ASCs$ + MID$(t$,k%+1)
UNTIL k% = 0
NEXT
url$ = "http://www.rosettacode.org/w/index.php?title=" + t$ + \
\ "&action=raw"
file$ = @tmp$ + "title.htm"
SYS UDTF, 0, url$, file$, 0, 0 TO fail%
IF fail% ERROR 100, "File download failed " + t$
examples% = 0
task% = OPENIN(file$)
WHILE NOT EOF#task%
IF INSTR(GET$#task%, "=={{header|") examples% += 1
ENDWHILE
CLOSE #task%
Total% += examples%
PRINT title$ ": " ; examples% " examples."
ENDIF
UNTIL i% = 0
i% = INSTR(a$, "cmcontinue=")
IF i% THEN
CLOSE #file%
j% = INSTR(a$, """", i%+1)
k% = INSTR(a$, """", j%+1)
url$ = "http://www.rosettacode.org/w/api.php?action=query" + \
\ "&list=categorymembers&cmtitle=Category:Programming_Tasks" + \
\ "&cmlimit=500&format=xml&cmcontinue=" + MID$(a$,j%+1,k%-j%)
REPEAT
i% = INSTR(url$, "|")
IF i% url$ = LEFT$(url$,i%-1) + "%7C" + MID$(url$,i%+1)
UNTIL i% = 0
file$ = @tmp$ + "tasks.xml"
SYS UDTF, 0, url$, file$, 0, 0 TO fail%
IF fail% ERROR 100, "File download failed (continue)"
file% = OPENIN(file$)
ENDIF
ENDWHILE
CLOSE #file%
PRINT ' "Total: " ; Total% " examples."
END
DEF FNhtml(h$)
IF LEFT$(h$,2) = "&#" THEN = CHR$(VALMID$(h$,3))
CASE h$ OF
WHEN """: = """"
ENDCASE
= h$
Sample output:
100 doors: 154 examples. 24 game: 53 examples. 24 game/Solve: 30 examples. 99 Bottles of Beer: 181 examples. A+B: 124 examples. Abstract type: 49 examples. Accumulator factory: 65 examples. Ackermann function: 126 examples. Active Directory/Connect: 12 examples. Active Directory/Search for a user: 13 examples. ...... XML/DOM serialization: 33 examples. XML/Input: 50 examples. XML/Output: 41 examples. XML/XPath: 33 examples. Y combinator: 51 examples. Yahoo! search interface: 13 examples. Yin and yang: 36 examples. Zebra puzzle: 11 examples. Zeckendorf number representation: 14 examples. Zig-zag matrix: 64 examples. Total: 27004 examples.
Bracmat
( ( get-page
=
. sys$(str$("wget -q -O wget.out \"" !arg \"))
& get$("wget.out",HT ML)
)
& get-page$"http://rosettacode.org/wiki/Category:Programming_Tasks"
: ? (table.?) ?tasklist (.table.) ?
& 0:?list
& whl
' ( !tasklist
: ?
( a
. (href.@(?:"/wiki/" ?href)) (title.?title)
& get-page$(str$("http://rosettacode.org/wiki/" !href))
: ?task
& 0:?cnt
& whl
' ( !task
: ?
( (span.(class.mw-headline) (id.?))
?span
(.span.)
?task
& !span
: ?
( a
. (href.@(?:"/wiki/Category:" ?))
(title.@(?:"Category:" ?))
)
@
(.a.)
?
)
& 1+!cnt:?cnt
)
& (!cnt.!title)+!list:?list
)
?tasklist
)
& lst$(list,taskfreq,NEW)
)
Output (in file tasqfreq
):
list= (2."OLE Automation") + (3."Canny edge detector") + ( 3 . "Continued fraction/Arithmetic/G(matrix NG, Contined Fraction N1, Contined Fraction N2)" ) + (4."Colour pinstripe/Printer") + (4."Vogel's approximation method") + (5."Catmull–Clark subdivision surface") + (5."Percolation/Bond percolation") + (5.Pinstripe/Printer) + (5."Zeckendorf arithmetic") + (6."Continued fraction/Arithmetic/G(matrix NG, Contined Fraction N)") + (6."Percolation/Mean cluster density") + (7."Bitmap/PPM conversion through a pipe") + (7."Deconvolution/2D+") + (7."K-d tree") .... + (125."Greatest element of a list") + (127."Averages/Arithmetic mean") + (131.Arrays) + (131."Increment a numerical string") + (132."Greatest common divisor") + (133.Loops/While) + (134."Conditional structures") + (136.Arithmetic/Integer) + (137.Loops/For) + (145.Loops/Infinite) + (147."Ackermann function") + (148."Reverse a string") + (152."A+B") + (152."Function definition") + (160."Empty program") + (163."Fibonacci sequence") + (164.Factorial) + (182.FizzBuzz) + (187."100 doors") + (188.Comments) + (216."99 Bottles of Beer") + (269."Hello world/Text");
C#
Object-oriented solution.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Net;
class Task {
private string _task;
private int _examples;
public Task(string task, int examples) {
_task = task;
_examples = examples;
}
public string Name {
get { return _task; }
}
public int Examples {
get { return _examples; }
}
public override string ToString() {
return String.Format("{0}: {1} examples.", this._task, this._examples);
}
}
class Program {
static List<string> GetTitlesFromCategory(string category, WebClient wc) {
string content = wc.DownloadString(
String.Format("http://www.rosettacode.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:{0}&cmlimit=500&format=json", category)
);
return new Regex("\"title\":\"(.+?)\"").Matches(content).Cast<Match>().Select(x => x.Groups[1].Value.Replace("\\/", "/")).ToList();
}
static string GetSourceCodeFromPage(string page, WebClient wc) {
return wc.DownloadString(
String.Format("http://www.rosettacode.org/w/index.php?title={0}&action=raw", page)
);
}
static void Main(string[] args) {
WebClient wc = new WebClient();
List<Task> tasks = new List<Task>();
List<string> tasknames = GetTitlesFromCategory("Programming_Tasks", wc);
foreach (string task in tasknames) {
try {
string content = GetSourceCodeFromPage(WebUtility.UrlEncode(task), wc);
int count = new Regex("=={{header", RegexOptions.IgnoreCase).Matches(content).Count;
Task t = new Task(task, count);
Console.WriteLine(t);
tasks.Add(t);
}
catch (Exception ex) {
Console.WriteLine("**** Unable to get task \"" + task + "\": " + ex.Message);
}
}
Console.WriteLine("\nTotal: {0} examples.", tasks.Select(x => x.Examples).Sum());
}
}
Clojure
(ns count-examples
(:import [java.net URLEncoder])
(:use [clojure.contrib.http.agent :only (http-agent string)]
[clojure.contrib.json :only (read-json)]
[clojure.contrib.string :only (join)]))
(defn url-encode [v] (URLEncoder/encode (str v) "utf-8"))
(defn rosettacode-get [path params]
(let [param-string (join "&" (for [[n v] params] (str (name n) "=" (url-encode v))))]
(string (http-agent (format "http://www.rosettacode.org/w/%s?%s" path param-string)))))
(defn rosettacode-query [params]
(read-json (rosettacode-get "api.php" (merge {:action "query" :format "json"} params))))
(defn list-cm
([params] (list-cm params nil))
([params continue]
(let [cm-params (merge {:list "categorymembers"} params (or continue {}))
result (rosettacode-query cm-params)]
(concat (-> result (:query) (:categorymembers))
(if-let [cmcontinue (-> result (:query-continue) (:categorymembers))]
(list-cm params cmcontinue))))))
(defn programming-tasks []
(let [result (list-cm {:cmtitle "Category:Programming_Tasks" :cmlimit 50})]
(map #(:title %) result)))
(defn task-count [task]
[task (count
(re-seq #"==\{\{header"
(rosettacode-get "index.php" {:action "raw" :title task})))])
(defn print-result []
(let [task-counts (map task-count (programming-tasks))]
(doseq [[task count] task-counts]
(println (str task ":") count)
(flush))
(println "Total: " (reduce #(+ %1 (second %2)) 0 task-counts))))
count-examples> (print-result)
100 doors: 73
24 game: 18
24 game/Solve: 14
99 Bottles of Beer: 89
Abstract type: 27
Accumulator factory: 23
Ackermann function: 73
Active Directory/Connect: 4
Active Directory/Search for a user: 3
Active object: 14
Add a variable to a class instance at runtime: 21
Address of a variable: 20
...
Total: 11216
nil
D
import tango.io.Stdout;
import tango.net.http.HttpClient;
import tango.net.http.HttpHeaders;
import tango.text.xml.Document;
import tango.text.Util;
alias HttpHeader.ContentLength CL;
auto url = "http://www.rosettacode.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml";
void main()
{
auto client = new HttpClient (HttpClient.Get, url);
client.open();
char[] mainData, tmp;
int total, i;
void cat(void[] content) { tmp ~= cast(char[]) content; }
if (client.isResponseOK) {
client.read(&cat, client.getResponseHeaders.getInt(CL));
mainData = tmp;
tmp = null;
auto doc = new Document!(char);
doc.parse(mainData);
foreach (n; doc.query.descendant("cm").attribute("title")) {
auto subClient = new HttpClient(HttpClient.Get,
"http://www.rosettacode.org/w/index.php?title=" ~
replace(n.value.dup, ' ', '_') ~ "&action=raw");
subClient.open();
if (! subClient.isResponseOK) {
Stderr (client.getResponse);
break;
}
subClient.read(&cat, subClient.getResponseHeaders.getInt(CL));
foreach (segment; patterns(cast(char[])tmp, "=={{header|")) i++;
--i;
if (i) --i;
Stdout.formatln ("{0,-40} - {}", n.value, i);
total += i;
tmp = null;
i = 0;
}
Stdout("total examples: ", total).newline;
} else {
Stderr (client.getResponse);
}
}
EGL
A graphical implementation with a grid showing the number of implementations for each Rosetta Code task as well as total task and implementation counts. Uses MediaWiki API service call to fetch tasks/categories in a JSON format and meets API data limit and continuation requirements to consume 100% of the items.
User Interface: RosettaCodeHandler.egl
package com.eglexamples.client;
import org.eclipse.edt.rui.widgets.*;
handler RosettaCodeHandler type RUIhandler{initialUI =[ui], title = "Rosetta Code Tasks and Counts"}
ui GridLayout{columns = 3, rows = 4, cellPadding = 4, children = [ b1, dg1, l1, l2, l3, l4 ]};
b1 Button{ layoutData = new GridLayoutData{ row = 1, column = 1 }, text = "Go!", onClick ::= b1_onClick };
l1 TextLabel{ layoutData = new GridLayoutData{ row = 1, column = 2 }, text = "Total Tasks:" };
l2 TextLabel{ layoutData = new GridLayoutData{ row = 1, column = 3 }, text = "0" };
l3 TextLabel{ layoutData = new GridLayoutData{ row = 2, column = 2 }, text = "Total Implementations:" };
l4 TextLabel{ layoutData = new GridLayoutData{ row = 2, column = 3 }, text = "0" };
dg1 DataGrid{ layoutData = new GridLayoutData{ row = 3, column = 1, horizontalSpan = 3 },
pageSize = 10, showScrollbar = true,
columns = [ new DataGridColumn{name = "title", displayName = "Task", width=220},
new DataGridColumn{name = "count", displayName = "Count", width=100} ] };
cmcontinue string?;
title string?;
allTasks Task[];
restBindingTasks IHttp? = new HttpRest{
restType = eglx.rest.ServiceType.TrueRest,
request.uri = "http://rosettacode.org/mw/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=1&format=json"};
restBindingPageDetail IHttp? = new HttpRest{
restType = eglx.rest.ServiceType.TrueRest,
request.uri = "http://rosettacode.org/mw/index.php"};
function b1_onClick(event Event in)
call ProxyFunctions.listTasks("") using restBindingTasks
returning to listTasksCallBack onException exceptionHandler;
end
function listTasksCallBack(retResult RosettaCodeJSON in)
title = retResult.query.categorymembers[1].title;
cmcontinue = retResult.queryContinue.categorymembers.cmcontinue;
call ProxyFunctions.fetchPageDetail(title) using restBindingPageDetail
returning to pageDetailCallBack onException exceptionHandler;
end
function pageDetailCallBack(pageResults string in)
count int = countSubstring("=={{header", pageResults);
allTasks.appendElement(new Task { title = title, count = count });
l2.text = l2.text as int + 1;
l4.text = l4.text as int + count;
if(cmcontinue != null)
call ProxyFunctions.listTasks(cmcontinue) using restBindingTasks
returning to listTasksCallBack onException exceptionHandler;
else
dg1.data = allTasks as any[];
end
end
function countSubstring(substr string in, str string in) returns(int)
if(str.length() > 0 and substr.length() > 0)
return (str.length() - str.replaceStr(subStr, "").length()) / subStr.length();
else
return 0;
end
end
function exceptionHandler(exp AnyException in)
end
end
record Task
title string;
count int;
end
Service Interface: ProxyFunctions.egl
package com.eglexamples.client;
library ProxyFunctions
function listTasks(continueLocation String in) returns (RosettaCodeJSON) {
@Rest{method = _GET, uriTemplate = "&cmcontinue={continueLocation}",
requestFormat = None, responseFormat = JSON}
}
end
function fetchPageDetail(title String in) returns (String) {
@Rest{method = _GET, uriTemplate = "?title={title}&action=raw",
requestFormat = None, responseFormat = None}
}
end
end
record RosettaCodeJSON
query Query;
queryContinue QueryContinue{JSONName = "query-continue"};
end
record Query
categorymembers Categorymembers[];
end
record Categorymembers
cmcontinue string?;
pageid int?;
ns int?;
title string?;
end
record QueryContinue
categorymembers Categorymembers;
end
Erlang
-module(rosseta_examples).
-include_lib("xmerl/include/xmerl.hrl").
-export([main/0]).
main() ->
application:start(inets),
Titles = read_titles(empty),
Result = lists:foldl(fun(Title,Acc) -> Acc + calculate_one(Title) end, 0, Titles),
io:format("Total: ~p examples.\n",[Result]),
application:stop(inets).
read_titles(CurrentContinue) ->
URL0 = "http://rosettacode.org/mw/api.php?" ++
"action=query&list=categorymembers&cmtitle=Category:Programming_Tasks" ++
"&cmlimit=500&format=xml",
URL =
case CurrentContinue of
empty -> URL0;
_ -> URL0 ++ "&cmcontinue=" ++ CurrentContinue
end,
{ok,Answer} = httpc:request(URL),
{Document,_} = xmerl_scan:string(lists:last(tuple_to_list(Answer))),
Continue =
[Value || #xmlAttribute{value = Value} <- xmerl_xpath:string("//@cmcontinue", Document)],
Titles =
[Value || #xmlAttribute{value = Value} <- xmerl_xpath:string("//@title", Document)],
case Continue of
[]->
Titles;
[ContValue | _] ->
Titles ++ read_titles(ContValue)
end.
calculate_one(Title0) ->
Title = replace_chars(Title0),
URL = "http://www.rosettacode.org/w/index.php?title=" ++
Title ++ "&action=raw",
case httpc:request(URL) of
{ok,Result} ->
{match,Found} =
re:run(lists:last(tuple_to_list(Result)), "\n=={{header(|)", [global]),
io:format("~ts: ~p examples.\n",[Title0,length(Found)]),
length(Found);
{error,socket_closed_remotely} ->
io:format("Socket closed remotely. Retry.\n"),
calculate_one(Title0)
end.
replace_chars(String) ->
replace_chars(String,[]).
replace_chars([$ | T],Acc) ->
replace_chars(T, [$_| Acc]);
replace_chars([$+| T],Acc) ->
replace_chars(T, lists:reverse("%2B") ++ Acc);
replace_chars([8211| T],Acc) ->
replace_chars(T, lists:reverse("%E2%80%93") ++ Acc);
replace_chars([Other| T],Acc) ->
replace_chars(T, [Other| Acc]);
replace_chars([],Acc) ->
lists:reverse(Acc).
Outputs:
> rosseta_examples:main(). 100 doors: 165 examples. 24 game: 56 examples. 24 game/Solve: 33 examples. ... Zebra puzzle: 12 examples. Zeckendorf number representation: 18 examples. Zig-zag matrix: 65 examples. Total: 28629 examples.
F#
Using asynchronous workflows to perform downloads concurrently:
#r "System.Xml.Linq.dll"
let uri1 = "http://www.rosettacode.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml"
let uri2 task = sprintf "http://www.rosettacode.org/w/index.php?title=%s&action=raw" task
[|for xml in (System.Xml.Linq.XDocument.Load uri1).Root.Descendants() do
for attrib in xml.Attributes() do
if attrib.Name.LocalName = "title" then
yield async {
let uri = uri2 (attrib.Value.Replace(" ", "_") |> System.Web.HttpUtility.UrlEncode)
use client = new System.Net.WebClient()
let! html = client.AsyncDownloadString(System.Uri uri)
let sols' = html.Split([|"{{header|"|], System.StringSplitOptions.None).Length - 1
lock stdout (fun () -> printfn "%s: %d examples" attrib.Value sols')
return sols' }|]
|> Async.Parallel
|> Async.RunSynchronously
|> fun xs -> printfn "Total: %d examples" (Seq.sum xs)
This is 21× faster than the python thanks to the concurrency.
Factor
Runs in about a minute. The number of threads is limited to 10 avoid cloudfare's protection mechanism.
USING: arrays assocs concurrency.combinators
concurrency.semaphores formatting hashtables http.client io
json.reader kernel math math.parser sequences splitting
urls.encoding ;
IN: rosetta-code.count-examples
CONSTANT: list-url "http://rosettacode.org/mw/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&cmprop=title&format=json"
: titles ( query -- titles )
"query" of "categorymembers" of [ "title" of ] map ;
: continued-url ( query -- url/f )
"query-continue" of "categorymembers" of
[ assoc>query list-url swap "&" glue ] [ f ] if* ;
: (all-programming-titles) ( titles url -- titles' url' )
http-get nip json> [ titles append ] [ continued-url ] bi
[ (all-programming-titles) ] [ f ] if* ;
: all-programming-titles ( -- titles ) { } list-url (all-programming-titles) drop ;
CONSTANT: content-base-url "http://rosettacode.org/mw/index.php?title=&action=raw"
: content-url ( title -- url )
" " "_" replace
"title" associate assoc>query
content-base-url swap "&" glue ;
: occurences ( seq subseq -- n ) split-subseq length 1 - ;
: count-examples ( title -- n )
content-url http-get nip "=={{header|" occurences ;
: print-task ( title n -- ) "%s: %d examples.\n" printf ;
: print-total ( assoc -- ) values sum "Total: %d examples.\n" printf ;
: fetch-counts ( titles -- assoc )
10 <semaphore> [
[ dup count-examples 2array ] with-semaphore
] curry parallel-map ;
: print-counts ( titles -- )
[ [ print-task ] assoc-each nl ] [ print-total ] bi ;
: rosetta-examples ( -- )
all-programming-titles fetch-counts print-counts ;
MAIN: rosetta-examples
Outputs:
100 doors: 169 examples. 24 game: 58 examples. ... Zeckendorf number representation: 22 examples. Zig-zag matrix: 66 examples. Total: 30745 examples.
Go
package main
import (
"bytes"
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strings"
)
func req(u string, foundCm func(string)) string {
resp, err := http.Get(u)
if err != nil {
fmt.Println(err) // connection or request fail
return ""
}
defer resp.Body.Close()
for p := xml.NewDecoder(resp.Body); ; {
t, err := p.RawToken()
switch s, ok := t.(xml.StartElement); {
case err == io.EOF:
return ""
case err != nil:
fmt.Println(err)
return ""
case !ok:
continue
case s.Name.Local == "cm":
for _, a := range s.Attr {
if a.Name.Local == "title" {
foundCm(a.Value)
}
}
case s.Name.Local == "categorymembers" && len(s.Attr) > 0 &&
s.Attr[0].Name.Local == "cmcontinue":
return url.QueryEscape(s.Attr[0].Value)
}
}
return ""
}
func main() {
taskQuery := "http://rosettacode.org/mw/api.php?action=query" +
"&format=xml&list=categorymembers&cmlimit=500" +
"&cmtitle=Category:Programming_Tasks"
continueAt := req(taskQuery, count)
for continueAt > "" {
continueAt = req(taskQuery+"&cmcontinue="+continueAt, count)
}
fmt.Printf("Total: %d examples.\n", total)
}
var marker = []byte("=={{header|")
var total int
func count(cm string) {
taskFmt := "http://rosettacode.org/mw/index.php?title=%s&action=raw"
taskEsc := url.QueryEscape(strings.Replace(cm, " ", "_", -1))
resp, err := http.Get(fmt.Sprintf(taskFmt, taskEsc))
var page []byte
if err == nil {
page, err = ioutil.ReadAll(resp.Body)
resp.Body.Close()
}
if err != nil {
fmt.Println(err)
return
}
examples := bytes.Count(page, marker)
fmt.Printf("%s: %d\n", cm, examples)
total += examples
}
- Output
- (May 25, 2011):
... Y combinator: 40 Yahoo! search interface: 10 Yin and yang: 18 Zig-zag matrix: 50 Total: 18290 examples.
Haskell
from HackageDB
import Network.Browser
import Network.HTTP
import Network.URI
import Data.List
import Data.Maybe
import Text.XML.Light
import Control.Arrow
justifyR w = foldl ((.return).(++).tail) (replicate w ' ')
showFormatted t n = t ++ ": " ++ justifyR 4 (show n)
getRespons url = do
rsp <- Network.Browser.browse $ do
setAllowRedirects True
setOutHandler $ const (return ()) -- quiet
request $ getRequest url
return $ rspBody $ snd rsp
getNumbOfExampels p = do
let pg = intercalate "_" $ words p
rsp <- getRespons $ "http://www.rosettacode.org/w/index.php?title=" ++ pg ++ "&action=raw"
let taskPage = rsp
countEx = length $ filter (=="=={{header|") $ takeWhile(not.null) $ unfoldr (Just. (take 11 &&& drop 1)) taskPage
return countEx
progTaskExamples = do
rsp <- getRespons "http://www.rosettacode.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml"
let xmls = onlyElems $ parseXML $ rsp
tasks = concatMap (map (fromJust.findAttr (unqual "title")). filterElementsName (== unqual "cm")) xmls
taskxx <- mapM getNumbOfExampels tasks
let ns = taskxx
tot = sum ns
mapM_ putStrLn $ zipWith showFormatted tasks ns
putStrLn $ ("Total: " ++) $ show tot
some output:
*Main> progTaskExamples
100 doors: 56
24 game: 11
24 game Player: 9
99 Bottles of Beer: 73
Abstract type: 23
Ackermann Function: 61
Active object: 9
...
Total: 9156
Icon and Unicon
The following code uses features exclusive to Unicon. This version handles all tasks, not just the first 500.
$define RCINDEX "http://rosettacode.org/mw/api.php?format=xml&action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500"
$define RCTASK "http://rosettacode.org/mw/index.php?action=raw&title="
$define RCUA "User-Agent: Unicon Rosetta 0.1"
$define RCXUA "X-Unicon: http://unicon.org/"
$define TASKTOT "* Total Tasks *"
$define TOTTOT "* Total Headers*"
link strings
link hexcvt
procedure main(A) # simple single threaded read all at once implementation
Tasks := table(0)
every task := taskNames() do {
Tasks[TASKTOT] +:= 1 # count tasks
every lang := languages(task) do { # count languages
Tasks[task] +:= 1
Tasks[TOTTOT] +:= 1
}
}
every insert(O := set(),key(Tasks)) # extract & sort keys
O := put(sort(O--set(TOTTOT,TASKTOT)),TASKTOT,TOTTOT) # move totals to end
every write(k := !O, " : ", Tasks[k]," examples.") # report
end
# Generate task names
procedure taskNames()
continue := ""
while \(txt := ReadURL(RCINDEX||continue)) do {
txt ? {
while tab(find("<cm ") & find(s :="title=\"")+*s) do
suspend tab(find("\""))\1
if tab(find("cmcontinue=")) then {
continue := "&"||tab(upto(' \t'))
}
else break
}
}
end
# Generate language headers in a task
procedure languages(task)
static WS
initial WS := ' \t'
page := ReadURL(RCTASK||CleanURI(task))
page ? while (tab(find("\n==")),tab(many(WS))|"",tab(find("{{"))) do {
header := tab(find("=="))
header ? {
while tab(find("{{header|")) do {
suspend 2(="{{header|",tab(find("}}")))\1
}
}
}
end
procedure CleanURI(u) #: clean up a URI
static tr,dxml # xml & http translation
initial {
tr := table()
every c := !string(~(&digits++&letters++'-_.!~*()/\'`')) do
tr[c] := "%"||hexstring(ord(c),2)
every /tr[c := !string(&cset)] := c
tr[" "] := "_" # wiki convention
every push(dxml := [],"&#"||right(ord(c := !"&<>'\""),3,"0")||";",c)
}
dxml[1] := u # insert URI as 1st arg
u := replacem!dxml # de-xml it
every (c := "") ||:= tr[!u] # reencode everything
c := replace(c,"%3E","'") # Hack to put single quotes back in
c := replace(c,"%26quot%3B","\"") # Hack to put double quotes back in
return c
end
procedure ReadURL(url) #: read URL into string
page := open(url,"m",RCUA,RCXUA) | stop("Unable to open ",url)
text := ""
if page["Status-Code"] < 300 then while text ||:= reads(page,-1)
else write(&errout,image(url),": ",
page["Status-Code"]," ",page["Reason-Phrase"])
close(page)
return text
end
strings provides replacem hexcvt provides hexstring
Sample Output for July 6, 2013 (abridged):
100 doors : 171 examples. 24 game : 60 examples. 24 game/Solve : 37 examples. 9 billion names of God the integer : 12 examples. 99 Bottles of Beer : 199 examples. A+B : 137 examples. Abstract type : 54 examples. Accumulator factory : 67 examples. Ackermann function : 137 examples. ... Y combinator : 56 examples. Yahoo! search interface : 18 examples. Yin and yang : 39 examples. Zebra puzzle : 12 examples. Zeckendorf arithmetic : 3 examples. Zeckendorf number representation : 21 examples. Zig-zag matrix : 67 examples. * Total Tasks * : 676 examples. * Total Headers* : 31146 examples.
J
Solution:
Using getCategoryMembers
from Find unimplemented tasks.
require 'web/gethttp'
getAllTaskSolnCounts=: monad define
tasks=. getCategoryMembers 'Programming_Tasks'
counts=. getTaskSolnCounts &> tasks
tasks;counts
)
getTaskSolnCounts=: monad define
makeuri=. 'http://www.rosettacode.org/w/index.php?title=' , ,&'&action=raw'
wikidata=. gethttp makeuri urlencode y
([: +/ '{{header|'&E.) wikidata
)
formatSolnCounts=: monad define
'tasks counts'=. y
tasks=. tasks , &.>':'
res=. ;:^:_1 tasks ,. (8!:0 counts) ,. <'examples.'
res , 'Total examples: ' , ": +/counts
)
Example Usage:
formatSolnCounts getAllTaskSolnCounts ''
100 doors: 61 examples.
24 game: 15 examples.
24 game Player: 11 examples.
99 Bottles of Beer: 76 examples.
...
Java
import java.util.ArrayList;
import ScreenScrape;
public class CountProgramExamples {
private static final String baseURL = "http://rosettacode.org/wiki/";
private static final String rootURL = "http://www.rosettacode.org/w/"
+ "api.php?action=query&list=categorymembers"
+ "&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml";
private static final String taskBegin = "title=\"";
private static final String taskEnd = "\"";
private static final String exmplBegin = "<span class=\"tocnumber\">";
private static final String exmplEnd = "</span>";
private static final String editBegin = "<span class=\"editsection\">";
/**
* @param args
*/
public static void main(String[] args) {
int exTotal = 0;
try {
// Get root query results
ArrayList<String> tasks = new ArrayList<String>();
ScreenScrape ss = new ScreenScrape();
String rootPage = ss.read(rootURL);
while (rootPage.contains(taskBegin)) {
rootPage = rootPage.substring(rootPage.indexOf(taskBegin)
+ taskBegin.length());
String title = rootPage.substring(0, rootPage.indexOf(taskEnd));
if (!title.contains("Category:")) {
tasks.add(title);
}
rootPage = rootPage.substring(rootPage.indexOf(taskEnd));
}
// Loop through each task and print count
for (String task : tasks) {
String title = task.replaceAll("'", "'");
String taskPage = ss.read(baseURL + title.replaceAll(" ", "_"));
int exSubTot;
if (taskPage.contains(exmplBegin)) {
int startPos = taskPage.lastIndexOf(exmplBegin)
+ exmplBegin.length();
String countStr = taskPage.substring(startPos,
taskPage.indexOf(exmplEnd, startPos));
exSubTot = Integer
.parseInt(countStr.contains(".") ? countStr
.substring(0, countStr.indexOf("."))
: countStr);
} else {
exSubTot = 0;
while (taskPage.contains(editBegin)) {
taskPage = taskPage.substring(taskPage
.indexOf(editBegin) + editBegin.length());
exSubTot++;
}
}
exTotal += exSubTot;
System.out.println(title + ": " + exSubTot + " examples.");
}
// Print total
System.out.println("\nTotal: " + exTotal + " examples.");
} catch (Exception e) {
System.out.println(title);
System.out.println(startPos + ":"
+ taskPage.indexOf(exmplEnd, startPos));
System.out.println(taskPage);
e.printStackTrace(System.out);
}
}
}
jq
jq does not duplicate the functionality of `curl` but works seamlessly with it, as illustrated by the following bash script. Note in particular the use of jq's `@uri` filter in the bash function `titles`.
#!/bin/bash
# Produce lines of the form: URI TITLE
function titles {
local uri="http://www.rosettacode.org/mw/api.php?action=query&list=categorymembers"
uri+="&cmtitle=Category:Programming_Tasks&cmlimit=5000&format=json"
curl -Ss "$uri" |
jq -r '.query.categorymembers[] | .title | "\(@uri) \(.)"'
}
# Syntax: count URI
function count {
local uri="$1"
curl -Ss "http://rosettacode.org/mw/index.php?title=${uri}&action=raw" |
jq -R -n 'reduce (inputs|select(test("=={{header\\|"))) as $x(0; .+1)'
}
local n=0 i
while read uri title
do
i=$(count "$uri")
echo "$title: $i examples."
n=$((n + i))
done < <(titles)
echo Total: $n examples.
- Output:
100 doors: 252 examples. 15 Puzzle Game: 36 examples. 2048: 24 examples. ... Order two numerical lists: 65 examples. Ordered Partitions: 28 examples. Ordered words: 85 examples. Palindrome detection: 136 examples. Total: 32416 examples.
Julia
Output by page is too long, so summaries only output shown.
using HTTP, JSON, Dates
rosorg = "http://rosettacode.org"
qURI = "/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=json"
qdURI = "/w/api.php?action=query&list=categorymembers&cmtitle=Category:Draft_Programming_Tasks&cmlimit=500&format=json"
sqURI = rosorg * "/wiki/"
topages(js, v) = for d in js["query"]["categorymembers"] push!(v, sqURI * replace(d["title"], " " => "_")) end
function getpages(uri)
wikipages = Vector{String}()
response = HTTP.request("GET", rosorg * uri)
if response.status == 200
fromjson = JSON.parse(String(response.body))
topages(fromjson, wikipages)
while haskey(fromjson, "continue")
cmcont, cont = fromjson["continue"]["cmcontinue"], fromjson["continue"]["continue"]
response = HTTP.request("GET", rosorg * uri * "&cmcontinue=$cmcont&continue=$cont")
fromjson = JSON.parse(String(response.body))
topages(fromjson, wikipages)
end
end
wikipages
end
function processtaskpages(wpages, verbose=false)
totalexamples = 0
for pag in wpages
response = HTTP.request("GET", pag)
if response.status == 200
n = length(collect(eachmatch(r"span class=\"mw-headline\"", String(response.body))))
if verbose
println("Wiki page $pag => $n examples.")
end
totalexamples += n
end
end
println("Total of $totalexamples on $(length(wpages)) task pages.\n")
end
println("Programming examples at $(DateTime(now())):")
qURI |> getpages |> processtaskpages
println("Draft programming tasks:")
qdURI |> getpages |> processtaskpages
- Output:
Programming examples at 2019-02-16T21:04:15.583: Total of 66388 on 928 task pages. Draft programming tasks: Total of 3385 on 216 task pages.
Lasso
local(root = json_deserialize(curl('http://rosettacode.org/mw/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=10&format=json')->result))
local(tasks = array, title = string, urltitle = string, thiscount = 0, totalex = 0)
with i in #root->find('query')->find('categorymembers') do => {^
#thiscount = 0
#title = #i->find('title')
#urltitle = #i->find('title')
#urltitle->replace(' ','_')
#title+': '
local(src = curl('http://rosettacode.org/mw/index.php?title='+#urltitle->asBytes->encodeurl+'&action=raw')->result->asString)
#thiscount = (#src->split('=={{header|'))->size - 1
#thiscount < 0 ? #thiscount = 0
#thiscount + ' examples.'
#totalex += #thiscount
'\r'
^}
'Total: '+#totalex+' examples.'
- Output:
Collecting 10 results:
100_doors: 176 examples. 24_game: 58 examples. 24_game/Solve: 35 examples. 9_billion_names_of_God_the_integer: 16 examples. 99_Bottles_of_Beer: 210 examples. A+B: 142 examples. Abstract_type: 54 examples. Accumulator_factory: 70 examples. Ackermann_function: 143 examples. Active_Directory/Connect: 15 examples. Total: 919 examples.
LiveCode
1. Add a button to a stack, put the following into the mouseUp
2. Add a text field called "tasks"
n.b. The list of tasks is limited to 10 for demo purposes
on mouseUp
put empty into fld "taskurls"
put URL "http://rosettacode.org/mw/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=10&format=xml" into apixml
put revXMLCreateTree(apixml,true,true,false) into pDocID
put "/api/query/categorymembers/cm" into pXPathExpression
repeat for each line xmlnode in revXMLEvaluateXPath(pDocID, pXPathExpression)
put revXMLAttribute(pDocID,xmlnode,"title") into pgTitle
put revXMLAttribute(pDocID,xmlnode,"pageid") into pageId
put "http://www.rosettacode.org/w/index.php?title=" & urlEncode(pgTitle) & "&action=raw" into taskURL
put URL taskURL into taskPage
filter lines of taskPage with "=={{header|*"
put the number of lines of taskPage into taskTotal
put pgTitle & comma & taskTotal & cr after fld "tasks"
add taskTotal to allTaskTotal
end repeat
put "Total" & comma & allTaskTotal after fld "tasks"
end mouseUp
Maple
ConvertUTF8 := proc( str )
local i, tempstring, uniindex;
try
tempstring := str;
uniindex := [StringTools:-SearchAll("\u",str)];
if uniindex <> [] then
for i in uniindex do
tempstring := StringTools:-Substitute(tempstring, str[i..i+5], UTF8:-unicode(str[i+2..i+5]));
end do:
end if;
return tempstring;
catch:
return str;
end try;
end proc:
print_examples := proc(lst)
local task, count, url, headers, item;
for task in lst do
count := 0:
url := cat("http://www.rosettacode.org/mw/index.php?title=", StringTools:-Encode(StringTools:-SubstituteAll(task["title"], " ", "_"), 'percent'), "&action=raw"):
headers := [StringTools:-SearchAll("=={{header|",URL:-Get(url))]:
for item in headers do
count++:
end do:
printf("%s has %d examples\n",ConvertUTF8(task["title"]), count);
end do:
end proc:
x := JSON:-ParseFile("http://rosettacode.org/mw/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=20&format=json"):
print_examples(x["query"]["categorymembers"]);
while(assigned(x["continue"]["cmcontinue"])) do
continue := x["continue"]["cmcontinue"]:
more_tasks:= cat("http://rosettacode.org/mw/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=20&format=json", "&continue=", x["continue"]["continue"], "&cmcontinue=", x["continue"]["cmcontinue"]):
x := JSON:-ParseFile(more_tasks):
print_examples(x["query"]["categorymembers"]);
end do:
- Output:
100 doors has 267 examples 15 Puzzle Game has 42 examples 15 puzzle solver has 4 examples 2048 has 34 examples 24 game has 88 examples 24 game/Solve has 54 examples 4-rings or 4-squares puzzle has 33 examples 9 billion names of God the integer has 42 examples 99 Bottles of Beer has 291 examples A+B has 224 examples ABC Problem has 104 examples Abstract type has 77 examples Abundant, deficient and perfect number classifications has 69 examples Accumulator factory has 97 examples Ackermann function has 194 examples Active Directory/Connect has 24 examples Active Directory/Search for a user has 16 examples Active object has 37 examples Add a variable to a class instance at runtime has 51 examples Address of a variable has 69 examples AKS test for primes has 55 examples Align columns has 97 examples Aliquot sequence classifications has 32 examples Almost prime has 58 examples Amb has 35 examples Amicable pairs has 69 examples Anagrams has 99 examples Anagrams/Deranged anagrams has 63 examples Angle difference between two bearings has 24 examples Animate a pendulum has 55 examples Animation has 61 examples Anonymous recursion has 86 examples Append a record to the end of a text file has 36 examples Apply a callback to an array has 144 examples Apply a digital filter (direct form II transposed) has 14 examples Arbitrary-precision integers (included) has 84 examples Archimedean spiral has 40 examples Arena storage pool has 25 examples Arithmetic evaluation has 51 examples Arithmetic-geometric mean has 93 examples Arithmetic-geometric mean/Calculate Pi has 23 examples Arithmetic/Complex has 101 examples Arithmetic/Integer has 176 examples Arithmetic/Rational has 59 examples Array concatenation has 159 examples Array length has 124 examples Arrays has 188 examples Assertions has 96 examples Associative array/Creation has 128 examples Associative array/Iteration has 107 examples Atomic updates has 38 examples Average loop length has 34 examples Averages/Arithmetic mean has 168 examples Averages/Mean angle has 63 examples Averages/Mean time of day has 50 examples Averages/Median has 103 examples Averages/Mode has 76 examples Averages/Pythagorean means has 96 examples Averages/Root mean square has 111 examples Averages/Simple moving average has 78 examples AVL tree has 18 examples Babbage problem has 80 examples Balanced brackets has 112 examples Balanced ternary has 34 examples Barnsley fern has 39 examples Benford's law has 58 examples Bernoulli numbers has 43 examples ... Variable size/Set has 37 examples Variable-length quantity has 35 examples Variables has 109 examples Variadic function has 94 examples Vector products has 77 examples Verify distribution uniformity/Chi-squared test has 21 examples Verify distribution uniformity/Naive has 40 examples Video display modes has 13 examples Vigenère cipher has 0 examples Vigenère cipher/Cryptanalysis has 0 examples Visualize a tree has 35 examples Vogel's approximation method has 12 examples Voronoi diagram has 32 examples Walk a directory/Non-recursively has 84 examples Walk a directory/Recursively has 75 examples Water collected between towers has 28 examples Web scraping has 75 examples Window creation has 81 examples Window creation/X11 has 23 examples Window management has 19 examples Wireworld has 47 examples Word search has 9 examples Word wrap has 63 examples World Cup group stage has 14 examples Write entire file has 53 examples Write float arrays to a text file has 64 examples Write language name in 3D ASCII has 59 examples Write to Windows event log has 23 examples Xiaolin Wu's line algorithm has 25 examples XML/DOM serialization has 45 examples XML/Input has 68 examples XML/Output has 55 examples XML/XPath has 52 examples Y combinator has 81 examples Yahoo! search interface has 19 examples Yin and yang has 53 examples Zebra puzzle has 39 examples Zeckendorf arithmetic has 10 examples Zeckendorf number representation has 57 examples Zero to the zero power has 94 examples Zhang-Suen thinning algorithm has 26 examples Zig-zag matrix has 92 examples
Mathematica/Wolfram Language
TaskList = Flatten[
Import["http://rosettacode.org/wiki/Category:Programming_Tasks", "Data"][[1, 1]]];
Print["Task \"", StringReplace[#, "_" -> " "], "\" has ",
Length@Select[Import["http://rosettacode.org/wiki/" <> #, "Data"][[1,2]],
StringFreeQ[#, __ ~~ "Programming Task" | __ ~~ "Omit"]& ], " example(s)"]&
~Map~ StringReplace[TaskList, " " -> "_"]
returns:
Task "100 doors" has 143 example(s) Task "24 game" has 55 example(s) Task "24 game/Solve" has 35 example(s) ...
MATLAB / Octave
The function count_examples() need to be saved in a file count_examples.m and its directory need to be included in the path.
function c = count_examples(url)
c = 0;
[s, success] = urlread (url);
if ~success, return; end;
c = length(strfind(s,'<h2><span class='));
end;
% script
s = urlread ('http://rosettacode.org/wiki/Category:Programming_Tasks');
pat = '<li><a href="/wiki/';
ix = strfind(s,pat)+length(pat)-6;
for k = 1:length(ix);
% look through all tasks
e = find(s(ix(k):end)==34,1)-2;
t = s(ix(k)+[0:e]); % task
c = count_examples(['http://rosettacode.org',t]);
printf('Task "%s" has %i examples.\n',t(7:end), c);
end;
Output:
Task "100_doors" has 137 examples. Task "24_game" has 45 examples. Task "24_game/Solve" has 28 examples. Task "99_Bottles_of_Beer" has 156 examples. Task "A%2BB" has 105 examples. ...
Nim
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."
- Output:
100 doors: 326 examples. 100 prisoners: 55 examples. 15 puzzle game: 71 examples. 15 puzzle solver: 18 examples. 2048: 57 examples. 21 game: 37 examples. 24 game: 100 examples. 24 game/Solve: 64 examples. 4-rings or 4-squares puzzle: 57 examples. 9 billion names of God the integer: 60 examples. 99 bottles of beer: 347 examples. A+B: 278 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 [...]
Objeck
use HTTP;
use XML;
class RosettaCount {
function : Main(args : String[]) ~ Nil {
taks_xml := HttpGet("http://rosettacode.org/mw/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml");
parser := XmlParser->New(taks_xml);
if(parser->Parse()) {
task_names := parser->FindElements("/api/query/categorymembers/cm");
if(task_names <> Nil) {
each(i : task_names) {
task_name := task_names->Get(i)->As(XmlElement)->GetAttribute("title")->GetValue();
task_url := "http://rosettacode.org/mw/index.php?title=";
task_url->Append(task_name);
task_url->Append("&action=raw");
task := HttpGet(task_url);
counts := task->FindAll("=={{header|");
if(counts->Size() > 0) {
IO.Console->Print(UrlUtility->Decode(task_name))->Print(": ")->PrintLine(counts->Size());
};
};
};
};
}
function : HttpGet(url : String) ~ String {
xml := "";
client := HttpClient->New();
lines := client->Get(url);
each(i : lines) {
xml->Append(lines->Get(i)->As(String));
};
return xml;
}
}
Output:
Amb: 28 Anagrams: 71 Animation: 42 Arithmetic/Complex: 80 Arithmetic/Integer: 136 Arithmetic/Rational: 45 Arrays: 131 Assertions: 75 Averages/Median: 82 Averages/Mode: 61 Bitmap: 58 Bitmap/Histogram: 22 Calendar: 30 Catamorphism: 27 Classes: 77 Collections: 59 ...
OCaml
execute with:
ocaml str.cma unix.cma -I +pcre pcre.cma -I +netsys netsys.cma -I +equeue equeue.cma \ -I +netstring netstring.cma -I +netclient netclient.cma -I +xml-light xml-light.cma countex.ml
or with the findlib package one can compile with:
ocamlfind opt -linkpkg -package str,unix,xml-light,netclient countex.ml -o countex.opt
open Http_client.Convenience
let repl_quote s =
let reg = Str.regexp_string "'" in
(Str.global_replace reg "%27" s)
let repl_space s =
let s = String.copy s in
for i = 0 to pred(String.length s) do
if s.[i] = ' ' then s.[i] <- '_'
done;
(s)
(* or in OCaml 4.00+:
let repl_space = String.map (fun c -> if c = ' ' then '_' else c)
*)
let count_ex s =
let pat = Str.regexp_string "=={{header|" in
let rec aux n p =
try
let p = Str.search_forward pat s p in
aux (n+1) (p+1)
with Not_found -> (n)
in
aux 0 0
let get_child child xml =
let child =
List.find
(function Xml.Element (tag,_,_) when tag = child -> true | _ -> false) xml
in
Xml.children child
let () =
let url = "http://www.rosettacode.org/w/api.php?action=query&list=categorymembers&\
cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml" in
let xml = Xml.parse_string (http_get url) in
let total = ref 0 in
at_exit (fun () -> Printf.printf "\n Total: %d\n" !total);
let f = function
| Xml.Element ("cm", attrs, _) ->
(try
let _title = List.assoc "title" attrs in
let title = repl_quote (repl_space _title) in
let url = "http://www.rosettacode.org/w/index.php?title="^ title ^"&action=raw" in
let n = count_ex (http_get url) in
Printf.printf "%s: %d\n%!" _title n;
total := n + !total;
with Http_client.Http_error (404, _) -> ())
| _ -> ()
in
match xml with
| Xml.Element ("api", _, ch) ->
let query = get_child "query" ch in
let catmb = get_child "categorymembers" query in
List.iter f catmb
| _ -> ()
outputs:
100 doors: 56 24 game: 11 24 game Player: 9 99 Bottles of Beer: 73 Abstract type: 23 Ackermann Function: 61 ... XML Reading: 22 XML and XPath: 18 Xiaolin Wu's line algorithm: 3 Y combinator: 23 Yuletide Holiday: 32 Zig Zag: 29 Total: 9106
Oz
declare
[HTTPClient] = {Module.link ['x-ozlib://mesaros/net/HTTPClient.ozf']}
[XMLParser] = {Module.link ['x-oz://system/xml/Parser.ozf']}
[StringX] = {Module.link ['x-oz://system/String.ozf']}
[Regex] = {Module.link ['x-oz://contrib/regex']}
AllTasksUrl = "http://rosettacode.org/mw/api.php?action=query&list="#
"categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml"
proc {Main}
AllTasks = {Parse {GetPage AllTasksUrl}}
TaskTitles = {GetTitles AllTasks}
Total = {NewCell 0}
in
for Task in TaskTitles do
TaskPage = {GetPage {TaskUrl Task}}
RE = {Regex.compile "{{header\\|" [extended newline icase]}
NumMatches = {Length {Regex.allMatches RE TaskPage}}
in
{System.showInfo Task#": "#NumMatches#" examples."}
Total := @Total + NumMatches
end
{System.showInfo "Total: "#@Total#" examples."}
end
fun {TaskUrl Task}
"http://rosettacode.org/mw/index.php?"#
"title="#{PercentEncode {StringX.replace Task " " "_"}}#
"&action=raw"
end
%% GetPage
local
Client = {New HTTPClient.urlGET init(inPrms(toFile:false toStrm:true) _)}
in
fun {GetPage RawUrl}
Url = {VirtualString.toString RawUrl}
OutParams
HttpResponseParams
in
{Client getService(Url ?OutParams ?HttpResponseParams)}
OutParams.sOut
end
end
%% Parse
local
Parser = {New XMLParser.parser init}
in
fun {Parse Xs} {Parser parseVS(Xs $)} end
end
fun {GetTitles Doc}
CMs = Doc.2.1.children.1.children.1.children
fun {Attributes element(attributes:As ...)} As end
fun {IsTitle attribute(name:N ...)} N == title end
in
{Map {Filter {Flatten {Map CMs Attributes}} IsTitle}
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
in
{Main}
Example output:
100 doors: 86 examples. 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.
Perl
use HTTP::Tiny;
my $site = "http://rosettacode.org";
my $list_url = "/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml";
my $response = HTTP::Tiny->new->get("$site$list_url");
for ($response->{content} =~ /cm.*?title="(.*?)"/g) {
(my $slug = $_) =~ tr/ /_/;
my $response = HTTP::Tiny->new->get("$site/wiki/$slug");
my $count = () = $response->{content} =~ /toclevel-1/g;
print "$_: $count examples\n";
}
use Mojo::UserAgent;
my $site = "http://rosettacode.org";
my $list_url = "/mw/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml";
my $ua = Mojo::UserAgent->new;
$ua->get("$site$list_url")->res->dom->find('cm')->each(sub {
(my $slug = $_->{title}) =~ tr/ /_/;
my $count = $ua->get("$site/wiki/$slug")->res->dom->find("#toc .toclevel-1")->size;
say "$_->{title}: $count examples";
});
Phix
First, some common code used by several tasks:
-- -- demo\rosetta\rosettacode_cache.e -- ================================ -- -- Common routines for handling rc_cache etc. -- without js -- (libcurl, file i/o, peek, progress..) include builtins\timedate.e constant day = timedelta(days:=1) integer refresh_cache = 21*day -- 0 for always [NB refresh_cache += timedelta(days:=1) below] function days(atom delta) integer d = ceil(delta/day) return sprintf("%d day%s",{d,iff(d=1?"":"s")}) end function constant {hex,ascii} = columnize({{"%22",`"`}, {"%27","'"}, {"%2A","*"}, {"%2B","+"}, {"%3A",":"}, {"%5E",`^`}, {"%E2%80%93","-"}, {"%E2%80%99","'"}, {"%C3%A8","e"}, {"%C3%A9","e"}, {"%C3%B6","o"}, {"%C5%91","o"}, {""",`"`}, {"'","'"}, {"_"," "}}) global function html_clean(string s) return substitute_all(s,hex,ascii) end function include builtins\libcurl.e atom curl = NULL, pErrorBuffer function write_callback(atom pData, integer size, nmemb, fn) integer bytes_written = size * nmemb puts(fn,peek({pData,bytes_written})) return bytes_written end function constant write_cb = call_back({'+', write_callback}) global string wastitle = "" -- don't clobber "NEED EDITING"/Downloading messages global integer show_title = progress global function open_download(string filename, url, integer i=0, n=0) object text bool refetch = false string why = "not found" filename = join_path({"rc_cache",filename}) if file_exists(filename) then -- use existing file if <= refresh_cache days old sequence last_mod = get_file_date(filename) atom delta = timedate_diff(last_mod,date()) refetch = true if delta>refresh_cache and not match(".hist",filename) then why = days(delta) & " > " & days(refresh_cache) elsif get_file_size(filename)=0 then why = "filesize of 0" else text = trim(get_text(filename)) if not sequence(text) then why = "no text" elsif length(text)<10 then why = "<10 bytes" else refetch = false end if end if else refetch = true string directory = get_file_path(filename) if get_file_type(directory)!=FILETYPE_DIRECTORY then if not create_directory(directory,make_parent:=true) then crash("cannot create %s directory",{directory}) end if end if end if if refetch then wastitle = "x" -- don't clobber string nofn = iff(n?sprintf("(%d/%d, %.1f%%) ",{i,n,i/n*100}):""), title = sprintf("Downloading %s%s (%s)...",{nofn,html_clean(filename),why}) show_title(title) if curl=NULL then curl_global_init() curl = curl_easy_init() pErrorBuffer = allocate(CURL_ERROR_SIZE) curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, pErrorBuffer) curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb) end if url = substitute(url,"%3A",":") url = substitute(url,"%2A","*") curl_easy_setopt(curl, CURLOPT_URL, url) integer fn = open(filename,"wb") assert(fn!=-1,"cannot open "&filename) curl_easy_setopt(curl, CURLOPT_WRITEDATA, fn) while true do CURLcode res = curl_easy_perform(curl) if res=CURLE_OK then exit end if string error = sprintf("%d",res) if res=CURLE_COULDNT_RESOLVE_HOST then error &= " [CURLE_COULDNT_RESOLVE_HOST]" end if progress("Error %s downloading file, retry?(Y/N):",{error}) if lower(wait_key())!='y' then abort(0) end if printf(1,"Y\n") end while close(fn) refresh_cache += timedelta(days:=1) -- did I mention it is slow? text = get_text(filename) end if return text end function global function open_category(string filename, integer i=0, n=0) return open_download(filename&".htm","http://rosettacode.org/wiki/Category:"&filename,i,n) end function global function dewiki(string s, sequence exclude={}) -- extract tasks from eg `<li><a href="/wiki/100_doors"` sequence tasks = {} integer start = 1, finish = match(`<div class="printfooter">`,s) s = s[1..finish-1] while true do start = match(`<li><a href="/wiki/`,s,start) if start=0 then exit end if start += length(`<li><a href="/wiki/`) finish = find('"',s,start) string task = s[start..finish-1] task = substitute_all(task,{"*",":"},{"%2A","%3A"}) tasks = append(tasks,task) start = finish+1 end while return tasks end function global procedure curl_cleanup() if curl!=NULL then curl_easy_cleanup(curl) free(pErrorBuffer) curl = NULL pErrorBuffer = NULL end if end procedure
The task itself:
-- -- demo\rosetta\Count_examples.exw -- =============================== -- -- (This uses a few '&' instead of/as well as 'a', fairly obviously for everyone's sanity..) -- Counts no of "{{he&der|" (nb not "=={{he&der|") via web api (but gets tasks via scraping). -- Since downloading all the pages can be very slow, this uses a cache. -- Limiting (notdone) by "Phix" fairly obviously speeds it up tenfold :-) -- without js -- (fairly obviously this will never ever run in a browser!) constant include_drafts = true, sort_by_count = false, -- notlang = "Phix" -- or "" (ie a zero length string) for all notlang = "" include rosettacode_cache.e function count_tasks() if get_file_type("rc_cache")!=FILETYPE_DIRECTORY then if not create_directory("rc_cache") then crash("cannot create rc_cache directory") end if end if -- note this lot use web scraping (as cribbed from a similar task) ... sequence tasks = dewiki(open_category("Programming_Tasks")) if include_drafts then tasks &= dewiki(open_category("Draft_Programming_Tasks")) tasks = sort(tasks) end if if length(notlang) then -- filter already done in specified language string langurl = "http://rosettacode.org/wiki/Category:"¬lang sequence done = dewiki(open_download(notlang&".htm",langurl)) integer k = 0 for i=1 to length(tasks) do string ti = tasks[i] integer d = find(ti,done) if not d then k += 1 tasks[k] = ti else done[d..d] = {} end if end for tasks = tasks[1..k] done = {} end if progress("%d tasks found\n",{length(tasks)}) -- ... whereas the individual tasks use the web api instead (3x smaller/faster) integer total_count = 0 sequence task_counts = repeat(0,length(tasks)) for i=1 to length(tasks) do string ti = tasks[i], url = sprintf("http://rosettacode.org/mw/index.php?title=%s&action=raw",{ti}), contents = open_download(ti&".raw",url), prev = "", curr integer count = 0, start = 1 while true do start = match(`{{hea`&`der|`,contents,start) if start=0 then exit end if -- -- skip duplicates/we also have to cope with eg -- =={{he&der|Python}}== \ -- ==={{he&der|Python}} Original=== } count -- ==={{he&der|Python}} Succinct=== } once -- ==={{he&der|Python}} Recursive === / -- =={{he&der|Mathematica}} / {{he&der|Wolfram Language}}== \ -- =={{he&der|Icon}} and {{he&der|Unicon}}== } count -- == {{he&der|Icon}} and {{he&der|Unicon}} == / both -- == {{he&der|Java}}== -- etc. Note however that this /does/ count eg -- ==={{he&der|Applesoft BASIC}}=== \ -- ==={{he&der|BASIC256}}=== } count -- ==={{he&der|Commodore BASIC}}=== } 'em -- ==={{he&der|IS-BASIC}}=== } all -- ==={{he&der|Sinclair ZX81 BASIC}}=== / -- curr = contents[start..match(`}}`,contents,start+1)] if curr!=prev then count += 1 end if prev = curr start += length(`{{hea`&`der|`) end while if sort_by_count then task_counts[i] = count elsif length(notlang) or i<=2 or i>=length(tasks)-1 or mod(i,200)=0 then progress("%s: %d\n",{html_clean(ti),count}) end if total_count += count if get_key()=#1B then progress("escape keyed\n") exit end if end for curl_cleanup() if sort_by_count then sequence tags = custom_sort(task_counts,tagset(length(tasks))) for i=length(tags) to 1 by -1 do integer ti = tags[i] progress("%s: %d\n",{html_clean(tasks[ti]),task_counts[ti]}) end for end if return total_count end function progress("Total: %d\n",{count_tasks()})
- Output:
(as of 30/2/22, showing first two, every 200th, and last two)
1523 tasks found 10001th prime: 33 100 doors: 337 Chowla numbers: 46 Exactly three adjacent 3 in lists: 27 Imaginary base numbers: 21 Monte Carlo methods: 87 Prime numbers which contain 123: 23 Smallest number k such that k+2^m is composite for all m less than k: 5 Trabb Pardo-Knuth algorithm: 83 Zig-zag matrix: 113 Zumkeller numbers: 36 Total: 88455
PicoLisp
(load "@lib/http.l")
(client "rosettacode.org" 80
"mw/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml"
(while (from " title=\"")
(let Task (till "\"")
(client "rosettacode.org" 80 (pack "wiki/" (replace Task " " "_"))
(let Cnt 0
(while (from "<span class=\"tocnumber\">")
(unless (sub? "." (till "<" T))
(inc 'Cnt) ) )
(out NIL (prinl (ht:Pack Task) ": " Cnt)) ) ) ) ) )
Output (05may10):
100 doors: 79 24 game: 21 24 game/Solve: 15 99 Bottles of Beer: 95 A+B: 37 Abstract type: 29 ...
PureBasic
Procedure handleError(value, msg.s)
If value = 0
MessageRequester("Error", msg)
End
EndIf
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
title$ = Mid(x1$, x2 + 7, 99)
title$ = Left(title$, FindString(title$, ">", 1) - 4)
unescapedTitle$ = UnescapeString(ReplaceString(title$, "'", "'"), #PB_String_EscapeXML)
encodedURL$ = URLEncoder("http://www.rosettacode.org/mw/index.php?title=" + unescapedTitle$ + "&action=raw")
If ReceiveHTTPFile(encodedURL$, "task.xml")
ReadFile(0, "task.xml")
While Not Eof(0)
y1$ = ReadString(0)
If FindString(y1$, "=={{header|", 1, #PB_String_NoCase)
totalExamples + 1
EndIf
Wend
CloseFile(0)
PrintN(unescapedTitle$ +": " + Str(totalExamples) + " examples")
totalTasks + totalExamples
totalExamples = 0
EndIf
EndIf
Until x2 = 0
;check for additional pages of tasks
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")
Input()
CloseConsole()
EndIf
Sample output:
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
Python
from urllib.request import urlopen, Request
import xml.dom.minidom
r = Request(
'https://www.rosettacode.org/mw/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml',
headers={'User-Agent': 'Mozilla/5.0'})
x = urlopen(r)
tasks = []
for i in xml.dom.minidom.parseString(x.read()).getElementsByTagName('cm'):
t = i.getAttribute('title').replace(' ', '_')
r = Request(f'https://www.rosettacode.org/mw/index.php?title={t}&action=raw',
headers={'User-Agent': 'Mozilla/5.0'})
y = urlopen(r)
tasks.append( y.read().lower().count(b'{{header|') )
print(t.replace('_', ' ') + f': {tasks[-1]} examples.')
print(f'\nTotal: {sum(tasks)} examples.')
Using Semantic MediaWiki
Here we use the ask API provided by the Semantic MediaWiki extension to query page properties rather than parse page content, producing subtly different counts to some other solutions. Maybe too different for this task.
We only count task examples that have a corresponding category page AND that page has the "Is Language" property set to True. In other words, Implemented In
+ Not Implemented In
+ Omitted From
is always equal to the total number of languages.
"""Count Rosetta Code tasks implementations using the Semantic MediaWiki API.
Works with Python >= 3.7."""
import json
import logging
from dataclasses import dataclass
from dataclasses import field
from datetime import datetime
from typing import Any
from typing import Dict
from typing import List
from typing import Optional
from typing import Set
from typing import Tuple
import requests
from requests.adapters import HTTPAdapter
from requests.adapters import Retry
logging.basicConfig(level=logging.WARN)
# See https://www.semantic-mediawiki.org/wiki/Help:API:ask
_SM_ASK: Dict[str, str] = {
"action": "ask",
"format": "json",
"formatversion": "2",
"api_version": "3",
}
_SM_ASK_REQUEST_BLOCK_SIZE = 500
@dataclass(frozen=True)
class Page:
# fulltext is the page's title, not the page content.
fulltext: str
fullurl: str
namespace: int
exists: str
displaytitle: str
@dataclass(frozen=True, eq=False)
class Lang(Page):
def __eq__(self, other: object) -> bool:
if isinstance(other, Lang):
return self.fullurl == other.fullurl
elif isinstance(other, str):
return self.fullurl == other
return False
def __hash__(self) -> int:
return hash(self.fullurl)
def unimplemented(self, tasks: Set["Task"]) -> Set["Task"]:
return {task for task in tasks if self.fullurl not in task.exclude}
def omitted_from(self, tasks: Set["Task"]) -> Set["Task"]:
return {task for task in tasks if self.fullurl in task.omitted_from}
@dataclass(frozen=True)
class Task(Page):
title: str
implemented_in: Set[Lang] = field(repr=False, compare=False)
omitted_from: Set[Lang] = field(repr=False, compare=False)
exclude: Set[Lang] = field(repr=False, compare=False)
def not_implemented_in(self, langs: Set[Lang]) -> Set[Lang]:
return langs.difference(self.exclude)
@dataclass
class TaskResponseBlock:
tasks: List[Task]
continue_offset: Optional[int] = None
@dataclass
class LanguageResponseBlock:
langs: List[Lang]
continue_offset: Optional[int] = None
def sm_ask_category(
session: requests.Session,
url: str,
category: str,
limit: int,
offset: int,
known_langs: Set[Lang],
) -> TaskResponseBlock:
query_params = {
**_SM_ASK,
"query": (
f"[[Category:{category}]]"
"|?Implemented in language"
"|?Omitted from language"
f"|limit={limit}"
f"|offset={offset}"
),
}
# Display some progress
log(f"ask [[Category:{category}]] offset={offset}")
response = session.get(url, params=query_params)
response.raise_for_status()
data = response.json()
handle_warnings_and_errors(data)
return _transform_implemented_in_response_data(data, known_langs)
def sm_ask_tasks(
session: requests.Session,
url: str,
limit: int,
offset: int,
known_langs: Set[Lang],
):
return sm_ask_category(
session, url, "Programming Tasks", limit, offset, known_langs
)
def sm_ask_drafts(
session: requests.Session,
url: str,
limit: int,
offset: int,
known_langs: Set[Lang],
):
return sm_ask_category(
session, url, "Draft Programming Tasks", limit, offset, known_langs
)
def sm_ask_languages(
session: requests.Session,
url: str,
limit: int,
offset: int,
) -> LanguageResponseBlock:
query_params = {
**_SM_ASK,
"query": (
"[[Is language::+]]"
"|?Implemented in language"
"|?Omitted from language"
f"|limit={limit}"
f"|offset={offset}"
),
}
# Display some progress
log(f"ask [[Is language::+]] offset={offset}")
response = session.get(url, params=query_params)
response.raise_for_status()
data = response.json()
handle_warnings_and_errors(data)
return _transform_language_response_data(data)
def sm_ask_all_tasks(
session: requests.Session, url: str, known_langs: Set[Lang]
) -> List[Task]:
block = sm_ask_tasks(
session,
url,
limit=_SM_ASK_REQUEST_BLOCK_SIZE,
offset=0,
known_langs=known_langs,
)
tasks = block.tasks
while block.continue_offset:
block = sm_ask_tasks(
session,
url,
limit=_SM_ASK_REQUEST_BLOCK_SIZE,
offset=block.continue_offset,
known_langs=known_langs,
)
tasks.extend(block.tasks)
return tasks
def sm_ask_all_drafts(
session: requests.Session, url: str, known_langs: Set[Lang]
) -> List[Task]:
block = sm_ask_drafts(
session,
url,
limit=_SM_ASK_REQUEST_BLOCK_SIZE,
offset=0,
known_langs=known_langs,
)
tasks = block.tasks
while block.continue_offset:
block = sm_ask_drafts(
session,
url,
limit=_SM_ASK_REQUEST_BLOCK_SIZE,
offset=block.continue_offset,
known_langs=known_langs,
)
tasks.extend(block.tasks)
return tasks
def sm_ask_all_languages(session: requests.Session, url: str) -> List[Lang]:
block = sm_ask_languages(
session,
url,
limit=_SM_ASK_REQUEST_BLOCK_SIZE,
offset=0,
)
langs = block.langs
while block.continue_offset:
block = sm_ask_languages(
session,
url,
limit=_SM_ASK_REQUEST_BLOCK_SIZE,
offset=block.continue_offset,
)
langs.extend(block.langs)
return langs
def _transform_implemented_in_response_data(
data: Any, known_langs: Set[Lang]
) -> TaskResponseBlock:
tasks: List[Task] = []
for result in data["query"]["results"]:
for task_title, task_page in result.items():
# We're excluding implementations that don't have a corresponding
# category page with an "Is Language" property.
implemented_in = {
Lang(**lang)
for lang in task_page["printouts"]["Implemented in language"]
}.intersection(known_langs)
omitted_from = (
{
Lang(**lang)
for lang in task_page["printouts"]["Omitted from language"]
}
.intersection(known_langs)
.difference(implemented_in)
)
tasks.append(
Task(
title=task_title,
implemented_in=implemented_in,
omitted_from=omitted_from,
fulltext=task_page["fulltext"],
fullurl=task_page["fullurl"],
namespace=task_page["namespace"],
exists=task_page["exists"],
displaytitle=task_page["displaytitle"],
exclude=implemented_in.union(omitted_from),
)
)
return TaskResponseBlock(
tasks=tasks, continue_offset=data.get("query-continue-offset", None)
)
def _transform_language_response_data(data: Any) -> LanguageResponseBlock:
langs: List[Lang] = []
for result in data["query"]["results"]:
for _, task_page in result.items():
langs.append(
Lang(
fulltext=task_page["fulltext"],
fullurl=task_page["fullurl"],
namespace=task_page["namespace"],
exists=task_page["exists"],
displaytitle=task_page["displaytitle"],
)
)
return LanguageResponseBlock(
langs=langs, continue_offset=data.get("query-continue-offset", None)
)
def get_session() -> requests.Session:
"""Setup a requests.Session with retries."""
retry_strategy = Retry(
total=5,
status_forcelist=[429, 500, 502, 503, 504],
allowed_methods=["HEAD", "GET", "OPTIONS"],
)
adapter = HTTPAdapter(max_retries=retry_strategy)
session = requests.Session()
session.mount("https://", adapter)
session.mount("http://", adapter)
return session
def log(msg: str) -> None:
print(f"{datetime.now().isoformat(' ', 'seconds')}: {msg}")
def handle_warnings_and_errors(data: Any) -> None:
if data.get("errors"):
for error in data["errors"]:
logging.error(json.dumps(error))
# legacy format
if data.get("error"):
logging.error(json.dumps(data["error"]))
if data.get("warnings"):
for warning in data["warnings"]:
logging.warning(json.dumps(warning))
def count_examples(url: str, n: int = 30) -> None:
"""Print a table to stdout containing implementation counts for the first
`n` tasks, sorted by number implementations (most to least)."""
session = get_session()
langs = set(sm_ask_all_languages(session, url))
tasks = sm_ask_all_tasks(session, url, langs)
drafts = sm_ask_all_drafts(session, url, langs)
all_tasks = [*tasks, *drafts]
# Map of task to (implemented in, not implemented in, omitted from)
counts: Dict[Task, Tuple[int, int, int]] = {}
# Running total of examples for all tasks. Where a language has multiple examples
# for a single tasks, we only count one example.
total: int = 0
for task in all_tasks:
total += len(task.implemented_in)
counts[task] = (
len(task.implemented_in),
len(task.not_implemented_in(langs)),
len(task.omitted_from),
)
# Pretty print
top = sorted(counts.items(), key=lambda it: it[1][0], reverse=True)[:n]
pad = max([len(task.fulltext) for task, _ in top])
print("\nKnown languages:", len(langs))
print("Total tasks:", len(all_tasks))
print("Total examples:", total)
print(f"{'Task':>{pad}} | Implemented In | Not Implemented In | Omitted From")
print("-" * (pad + 1), "+", "-" * 16, "+", "-" * 20, "+", "-" * 13, sep="")
for task, _counts in top:
implemented_in, not_implemented_in, omitted_from = _counts
print(
f"{task.fulltext:>{pad}} |"
f"{implemented_in:>15} |"
f"{not_implemented_in:>19} |"
f"{omitted_from:>13}"
)
if __name__ == "__main__":
import argparse
URL = "https://rosettacode.org/w/api.php"
parser = argparse.ArgumentParser(description="Count tasks on Rosetta Code.")
parser.add_argument(
"--rows",
"-n",
type=int,
default=30,
dest="n",
help="number of rows to display in the output table (default: 30)",
)
parser.add_argument(
"--url",
default=URL,
help=f"target MediaWiki URL (default: {URL})",
)
args = parser.parse_args()
count_examples(args.url, args.n)
- Output:
2023-02-11 11:09:34: ask [[Is language::+]] offset=0 2023-02-11 11:09:35: ask [[Is language::+]] offset=500 2023-02-11 11:09:36: ask [[Category:Programming Tasks]] offset=0 2023-02-11 11:09:47: ask [[Category:Programming Tasks]] offset=500 2023-02-11 11:10:04: ask [[Category:Programming Tasks]] offset=1000 2023-02-11 11:10:12: ask [[Category:Draft Programming Tasks]] offset=0 Known languages: 890 Total tasks: 1602 Total examples: 91075 Task | Implemented In | Not Implemented In | Omitted From --------------------------------+----------------+--------------------+------------- Hello world/Text | 498 | 392 | 0 99 bottles of beer | 371 | 519 | 0 100 doors | 334 | 555 | 1 FizzBuzz | 325 | 565 | 0 Fibonacci sequence | 308 | 582 | 0 Factorial | 302 | 588 | 0 Comments | 297 | 592 | 1 A+B | 293 | 597 | 0 Empty program | 274 | 616 | 0 Function definition | 254 | 634 | 2 Loops/Infinite | 254 | 635 | 1 Loops/For | 248 | 641 | 1 Loops/While | 244 | 645 | 1 Arrays | 237 | 652 | 1 Ackermann function | 234 | 653 | 3 Reverse a string | 231 | 657 | 2 Conditional structures | 223 | 666 | 1 Arithmetic/Integer | 213 | 677 | 0 Greatest common divisor | 213 | 677 | 0 Array concatenation | 208 | 682 | 0 Greatest element of a list | 208 | 682 | 0 Even or odd | 207 | 683 | 0 Loops/Downward for | 207 | 683 | 0 Sieve of Eratosthenes | 203 | 687 | 0 Increment a numerical string | 202 | 688 | 0 Integer comparison | 202 | 688 | 0 Repeat a string | 199 | 691 | 0 Boolean values | 198 | 691 | 1 Loops/For with a specified step | 198 | 691 | 1 Copy a string | 196 | 693 | 1
R
library(XML)
library(RCurl)
doc <- xmlInternalTreeParse("http://www.rosettacode.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml")
nodes <- getNodeSet(doc,"//cm")
titles = as.character( sapply(nodes, xmlGetAttr, "title") )
headers <- list()
counts <- list()
for (i in 1:length(titles)){
headers[[i]] <- getURL( paste("http://rosettacode.org/mw/index.php?title=", gsub(" ", "_", titles[i]), "&action=raw", sep="") )
counts[[i]] <- strsplit(headers[[i]],split=" ")[[1]]
counts[[i]] <- grep("\\{\\{header", counts[[i]])
cat(titles[i], ":", length(counts[[i]]), "examples\n")
}
cat("Total: ", length(unlist(counts)), "examples\n")
Racket
#lang racket
(require net/url net/uri-codec json (only-in racket/dict [dict-ref ref]))
(define (RC-get verb params)
((compose1 get-pure-port string->url format)
"http://rosettacode.org/mw/~a.php?~a" verb (alist->form-urlencoded params)))
(define (get-category catname)
(let loop ([c #f])
(define t
((compose1 read-json RC-get) 'api
`([action . "query"] [format . "json"]
[list . "categorymembers"] [cmtitle . ,(format "Category:~a" catname)]
[cmcontinue . ,(and c (ref c 'cmcontinue))] [cmlimit . "500"])))
(define (c-m key) (ref (ref t key '()) 'categorymembers #f))
(append (for/list ([page (c-m 'query)]) (ref page 'title))
(cond [(c-m 'query-continue) => loop] [else '()]))))
(printf "Total: ~a\n"
(for/sum ([task (get-category 'Programming_Tasks)])
(define s ((compose1 length regexp-match-positions*)
#rx"=={{" (RC-get 'index `([action . "raw"] [title . ,task]))))
(printf "~a: ~a\n" task s)
s))
Raku
(formerly Perl 6)
Retrieves counts for both Tasks and Draft Tasks. Save / Display results as a sortable wikitable rather than a static list. Click on a column header to sort on that column. To do a secondary sort, hold down the shift key and click on a second column header. Tasks have a gray (default) background, Draft Tasks have a yellow background.
This example tracks the top 50 languages by number of examples completed but only generates reports in tiers of 10. More than 10 gets too heavy and difficult to navigate.
Feed it parameters to control behaviour:
- :nf or :no-fetch to use saved information to generate the different reports. Recommended for the second, third, fourth, whatever report you are generating at any one time as fetching from the site is by far the most time consuming part.
- :t=1 (or :tier=1). :t=2, :t=3, whatever, up to :t=5 to control which tier of results to generate.
Language names with spaces will have underscores inserted to make the results uniform. Some oddball languages (lookin' at you Icon and Unicon) make it very difficult to obtain accurate results. The whole "conglomerate all of the Basic dialects together" movement of a few years ago also complicates things, but this should be pretty close.
For a full output, see Top tier, Second tier, Third tier, Fourth tier
use HTTP::UserAgent;
use URI::Escape;
use JSON::Fast;
use Lingua::EN::Numbers :short;
unit sub MAIN ( Bool :nf(:$no-fetch) = False, :t(:$tier) = 1 );
# Friendlier descriptions for task categories
my %cat = (
'Programming_Tasks' => 'Task',
'Draft_Programming_Tasks' => 'Draft'
);
my $client = HTTP::UserAgent.new;
$client.timeout = 10;
my $url = 'https://rosettacode.org/w';
my $hashfile = './RC_Task_count.json';
my $tablefile = "./RC_Task_count-{$tier}.txt";
my %tasks;
my @places = <① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩ ⑪ ⑫ ⑬ ⑭ ⑮ ⑯ ⑰ ⑱ ⑲ ⑳ ㉑ ㉒ ㉓ ㉔ ㉕
㉖ ㉗ ㉘ ㉙ ㉚ ㉛ ㉜ ㉝ ㉞ ㉟ ㊱ ㊲ ㊳ ㊴ ㊵ ㊶ ㊷ ㊸ ㊹ ㊺ ㊺ ㊻ ㊼ ㊽ ㊾ ㊿>;
# clear screen
run($*DISTRO.is-win ?? 'cls' !! 'clear') unless $no-fetch;
my %counts =
mediawiki-query(
$url, 'pages',
:generator<categorymembers>,
:gcmtitle<Category:Programming Languages>,
:gcmlimit<350>,
:rawcontinue(),
:prop<categoryinfo>
)
.map({ .<title>.subst(/^'Category:'/, '') => .<categoryinfo><pages> || 0 });
my $per-tier = 10;
my $which = (^$per-tier) »+» $per-tier * ($tier - 1);
my @top-n = %counts.sort( {-.value, .key} )[|$which].map: *.key.trans(' ' => '_');
# dump a copy to STDOUT, mostly for debugging purposes
say "<pre>{tc $tier.&ord-n} {$per-tier.&card} programming languages by number of task examples completed:";
say ' ', join ' ', .map( {("{(@places[|$which])[$_]} {@top-n[$_]}").fmt("%-15s")} ) for (^@top-n).batch(5);
say "</pre>\n";
unless $no-fetch {
note 'Retrieving task information...';
mkdir('./pages') unless './pages'.IO.e;
@top-n = %counts.sort( {-.value, .key} )[^@places].map: *.key.trans(' ' => '_');;
for %cat.keys.sort -> $cat {
mediawiki-query(
$url, 'pages',
:generator<categorymembers>,
:gcmtitle("Category:$cat"),
:gcmlimit<350>,
:rawcontinue(),
:prop<title>
).map({
my $page;
my $response;
loop {
$response = $client.get("{ $url }/index.php?title={ uri-escape .<title> }&action=raw");
if $response.is-success {
$page = $response.content;
last;
} else {
redo;
}
}
"./pages/{ uri-escape .<title>.subst(/' '/, '_', :g) }".IO.spurt($page);
my $lc = $page.lc.trans(' ' => '_');
my $count = +$lc.comb(/ ^^'==' <-[\n=]>* '{{header|' <-[}]>+? '}}==' \h* $$ /);
%tasks{.<title>} = {'cat' => %cat{$cat}, :$count};
%tasks{.<title>}<top-n> = (^@top-n).map( {
($lc.contains("==\{\{header|{@top-n[$_].lc}}}") or
# Deal with 3 part headers - {{header|F_Sharp|F#}}, {{header|C_Sharp|C#}}, etc.
$lc.contains("==\{\{header|{@top-n[$_].lc}|") or
# Icon and Unicon are their own special flowers
$lc.contains("}}_and_\{\{header|{@top-n[$_].lc}}}==") or
# Language1 / Language2 for shared entries (e.g. C / C++)
$lc.contains(rx/'}}''_'*'/''_'*'{{header|'$(@top-n[$_].lc)'}}=='/)) ??
(@places[$_]) !!
# Check if the task was omitted
$lc.contains("\{\{omit_from|{@top-n[$_].lc}") ?? 'O' !!
# The task is neither done or omitted
' '
} ).join;
print clear, 1 + $++, ' ', %cat{$cat}, ' ', .<title>;
})
}
print clear;
note "\nTask information saved to local file: {$hashfile.IO.absolute}";
$hashfile.IO.spurt(%tasks.&to-json);
}
# Load information from local file
%tasks = $hashfile.IO.e ?? $hashfile.IO.slurp.&from-json !! ( );
@top-n = %counts.sort( {-.value, .key} )[|$which].map: *.key.trans(' ' => '_');
# Convert saved task info to a table
note "\nBuilding table...";
my $count = +%tasks;
my $taskcnt = +%tasks.grep: *.value.<cat> eq %cat<Programming_Tasks>;
my $draftcnt = $count - $taskcnt;
my $total = sum %tasks{*}»<count>;
# Dump table to a file
my $out = open($tablefile, :w) or die "$!\n";
$out.say: "<pre>{tc $tier.&ord-n} {$per-tier.&card} programming languages by number of task examples completed:";
$out.say: ' ', join ' ', .map( {("{(@places[|$which])[$_]} {@top-n[$_]}").fmt("%-15s")} ) for (^@top-n).batch(5);
$out.say: "</pre>\n\n<div style=\"height:40em;overflow:scroll;\">";
# Add table boilerplate and caption
$out.say:
'{|class="wikitable sortable"', "\n",
"|+ As of { DateTime.new(time) } :: Tasks: { $taskcnt } ::<span style=\"background-color:#ffd\"> Draft Tasks:",
"{ $draftcnt } </span>:: Total Tasks: { $count } :: Total Examples: { $total }\n",
"!Count!!Task!!{(@places[|$which]).join('!!')}"
;
# Sort tasks by count then add row
for %tasks.sort: { [-.value<count>, .key] } -> $task {
$out.say:
( $task.value<cat> eq 'Draft'
?? "|- style=\"background-color: #ffc\"\n"
!! "|-\n"
),
"| { $task.value<count> }\n",
( $task.key ~~ /\d/
?? "|data-sort-value=\"{ $task.key.&naturally }\"| [[{uri-escape $task.key}|{$task.key}]]\n"
!! "| [[{uri-escape $task.key}|{$task.key}]]\n"
),
"|{ $task.value<top-n>.comb[|$which].join('||') }"
}
$out.say( "|}\n</div>" );
$out.close;
note "Table file saved as: {$tablefile.IO.absolute}";
sub mediawiki-query ($site, $type, *%query) {
my $url = "$site/api.php?" ~ uri-query-string(
:action<query>, :format<json>, :formatversion<2>, |%query);
my $continue = '';
gather loop {
my $response = $client.get("$url&$continue");
my $data = from-json($response.content);
take $_ for $data.<query>.{$type}.values;
$continue = uri-query-string |($data.<query-continue>{*}».hash.hash or last);
}
}
sub uri-query-string (*%fields) { %fields.map({ "{.key}={uri-escape .value}" }).join("&") }
sub naturally ($a) { $a.lc.subst(/(\d+)/, ->$/ {0~(65+$0.chars).chr~$0},:g) }
sub clear { "\r" ~ ' ' x 116 ~ "\r" }
- Abridged output:
Top ten programming language by number of task examples completed: ① Go ② Perl 6 ③ Kotlin ④ Python ⑤ Phix ⑥ Racket ⑦ Perl ⑧ C ⑨ Julia ⑩ Tcl
Count | Task | ① | ② | ③ | ④ | ⑤ | ⑥ | ⑦ | ⑧ | ⑨ | ⑩ |
---|---|---|---|---|---|---|---|---|---|---|---|
405 | Hello world/Text | ① | ② | ③ | ④ | ⑤ | ⑥ | ⑦ | ⑧ | ⑨ | ⑩ |
283 | 99 Bottles of Beer | ① | ② | ③ | ④ | ⑤ | ⑥ | ⑦ | ⑧ | ⑨ | ⑩ |
276 | FizzBuzz | ① | ② | ③ | ④ | ⑤ | ⑥ | ⑦ | ⑧ | ⑨ | ⑩ |
273 | 100 doors | ① | ② | ③ | ④ | ⑤ | ⑥ | ⑦ | ⑧ | ⑨ | ⑩ |
251 | Fibonacci sequence | ① | ② | ③ | ④ | ⑤ | ⑥ | ⑦ | ⑧ | ⑨ | ⑩ |
246 | Comments | ① | ② | ③ | ④ | ⑤ | ⑥ | ⑦ | ⑧ | ⑨ | ⑩ |
239 | Factorial | ① | ② | ③ | ④ | ⑤ | ⑥ | ⑦ | ⑧ | ⑨ | ⑩ |
223 | Empty program | ① | ② | ③ | ④ | ⑤ | ⑥ | ⑦ | ⑧ | ⑨ | ⑩ |
222 | A+B | ① | ② | ③ | ④ | ⑤ | ⑥ | ⑦ | ⑧ | ⑨ | ⑩ |
214 | Function definition | ① | ② | ③ | ④ | ⑤ | ⑥ | ⑦ | ⑧ | ⑨ | ⑩ |
Ring
# Project: Rosetta Code/Count examples
load "stdlib.ring"
ros= download("http://rosettacode.org/wiki/Category:Programming_Tasks")
pos = 1
num = 0
totalros = 0
rosname = ""
rostitle = ""
for n = 1 to len(ros)
nr = searchstring(ros,'<li><a href="/wiki/',pos)
if nr = 0
exit
else
pos = nr + 1
ok
nr = searchname(nr)
nr = searchtitle(nr)
next
see nl
see "Total: " + totalros + " examples." + nl
func searchstring(str,substr,n)
newstr=right(str,len(str)-n+1)
nr = substr(newstr, substr)
if nr = 0
return 0
else
return n + nr -1
ok
func searchname(sn)
nr2 = searchstring(ros,'">',sn)
nr3 = searchstring(ros,"</a></li>",sn)
rosname = substr(ros,nr2+2,nr3-nr2-2)
return sn
func searchtitle(sn)
st = searchstring(ros,"title=",sn)
rostitle = substr(ros,sn+19,st-sn-21)
rostitle = "rosettacode.org/wiki/" + rostitle
rostitle = download(rostitle)
sum = count(rostitle,"Edit section:")
num = num + 1
see "" + num + ". " + rosname + ": " + sum + " examples." + nl
totalros = totalros + sum
return sn
func count(cstring,dstring)
sum = 0
while substr(cstring,dstring) > 0
sum = sum + 1
cstring = substr(cstring,substr(cstring,dstring)+len(string(sum)))
end
return sum
Output:
1. 100 doors: 331 examples. 2. 15 Puzzle Game: 48 examples. 3. 15 puzzle solver: 18 examples. 4. 2048: 40 examples. 5. 24 game: 95 examples. 6. 24 game/Solve: 59 examples. 7. 4-rings or 4-squares puzzle: 42 examples. 8. 9 billion names of God the integer: 54 examples. 9. 99 Bottles of Beer: 393 examples. 10. A+B: 250 examples. ...... 872. XML/XPath: 54 examples. 873. Y combinator: 88 examples. 874. Yahoo! search interface: 20 examples. 875. Yin and yang: 59 examples. 876. Zebra puzzle: 58 examples. 877. Zeckendorf arithmetic: 11 examples. 878. Zeckendorf number representation: 64 examples. 879. Zero to the zero power: 100 examples. 880. Zhang-Suen thinning algorithm: 26 examples. 881. Zig-zag matrix: 112 examples. Total: 62677 examples.
Ruby
First, a RosettaCode module, saved as rosettacode.rb:
require 'open-uri'
require 'rexml/document'
module RosettaCode
URL_ROOT = "http://rosettacode.org/mw"
def self.get_url(page, query)
begin
# Ruby 1.9.2
pstr = URI.encode_www_form_component(page)
qstr = URI.encode_www_form(query)
rescue NoMethodError
require 'cgi'
pstr = CGI.escape(page)
qstr = query.map {|k,v|
"%s=%s" % [CGI.escape(k.to_s), CGI.escape(v.to_s)]}.join("&")
end
url = "#{URL_ROOT}/#{pstr}?#{qstr}"
p url if $DEBUG
url
end
def self.get_api_url(query)
get_url "api.php", query
end
def self.category_members(category)
query = {
"action" => "query",
"list" => "categorymembers",
"cmtitle" => "Category:#{category}",
"format" => "xml",
"cmlimit" => 500,
}
while true
url = get_api_url query
doc = REXML::Document.new open(url)
REXML::XPath.each(doc, "//cm") do |task|
yield task.attribute("title").value
end
continue = REXML::XPath.first(doc, "//query-continue")
break if continue.nil?
cm = REXML::XPath.first(continue, "categorymembers")
query["cmcontinue"] = cm.attribute("cmcontinue").value
end
end
end
Then, we implement the task with:
require 'rosettacode'
total_examples = 0
RosettaCode.category_members("Programming_Tasks") do |task|
url = RosettaCode.get_url("index.php", {"action" => "raw", "title" => task})
examples = open(url).read.scan("=={{header").length
puts "#{task}: #{examples}"
total_examples += examples
end
puts
puts "Total: #{total_examples}"
Run BASIC
html "<table border=1><tr bgcolor=wheat align=center><td>Num</td><td>Task</td><td>Examples</td></tr>"
a$ = httpGet$("http://rosettacode.org/wiki/Category:Programming_Tasks")
a$ = word$(a$,1,"</table></div>")
i = instr(a$,"<a href=""/wiki/")
i = instr(a$,"<a href=""/wiki/",i+1)
while i > 0
count = count + 1
i = instr(a$,"<a href=""/wiki/",i+1)
j = instr(a$,">",i+5)
a1$ = mid$(a$,i+15,j-i)
taskId$ = word$(a1$,1,"""")
task$ = word$(a1$,3,"""")
url$ = "http://rosettacode.org/wiki/";taskId$
a2$ = httpGet$(url$)
ii = instr(a2$,"<span class=""tocnumber"">")
jj = 0
while ii > 0
jj = ii
ii = instr(a2$,"<span class=""tocnumber"">",ii+10)
wend
if jj = 0 then
examp = 0
else
kk = instr(a2$,"<",jj+24)
examp = int(val(mid$(a2$,jj+24,kk-jj-24)))
end if
html "<tr><td align=right>";count;"</td><td>";task$;"</td><td align=right>";examp;"</td></tr>"
totExamp = totExamp + examp
wend
html "<tr bgcolor=wheat><td>**</td><td>** Total **</td><td align=right>";totExamp;"</td></tr></table>"
end
Num | Task | Examples |
1 | 100 doors | 165 |
2 | 24 game | 56 |
3 | 24 game/Solve | 34 |
4 | 99 Bottles of Beer | 192 |
5 | A+B | 129 |
6 | Abstract type | 51 |
7 | Accumulator factory | 65 |
8 | Ackermann function | 132 |
9 | Active Directory/Connect | 13 |
10 | Active Directory/Search for a user | 13 |
11 | Active object | 22 |
12 | Add a variable to a class instance at runtime | 37 |
... | ... | ... |
655 | Y combinator | 53 |
656 | Yahoo! search interface | 16 |
657 | Yin and yang | 38 |
658 | Zebra puzzle | 12 |
659 | Zeckendorf number representation | 18 |
660 | Zig-zag matrix | 65 |
** | ** Total ** | 28611 |
Rust
extern crate reqwest;
extern crate url;
extern crate rustc_serialize;
use std::io::Read;
use self::url::Url;
use rustc_serialize::json::{self, Json};
pub struct Task {
page_id: u64,
pub title: String,
}
#[derive(Debug)]
enum ParseError {
/// Something went wrong with the HTTP request to the API.
Http(reqwest::Error),
/// There was a problem parsing the API response into JSON.
Json(json::ParserError),
/// Unexpected JSON format from response
UnexpectedFormat,
}
impl From<json::ParserError> for ParseError {
fn from(error: json::ParserError) -> Self {
ParseError::Json(error)
}
}
impl From<reqwest::Error> for ParseError {
fn from(error: reqwest::Error) -> Self {
ParseError::Http(error)
}
}
fn construct_query_category(category: &str) -> Url {
let mut base_url = Url::parse("http://rosettacode.org/mw/api.php").unwrap();
let cat = format!("Category:{}", category);
let query_pairs = vec![("action", "query"),
("format", "json"),
("list", "categorymembers"),
("cmlimit", "500"),
("cmtitle", &cat),
("continue", "")];
base_url.query_pairs_mut().extend_pairs(query_pairs.into_iter());
base_url
}
fn construct_query_task_content(task_id: &str) -> Url {
let mut base_url = Url::parse("http://rosettacode.org/mw/api.php").unwrap();
let mut query_pairs =
vec![("action", "query"), ("format", "json"), ("prop", "revisions"), ("rvprop", "content")];
query_pairs.push(("pageids", task_id));
base_url.query_pairs_mut().extend_pairs(query_pairs.into_iter());
base_url
}
fn query_api(url: Url) -> Result<Json, ParseError> {
let mut response = try!(reqwest::get(url.as_str()));
// Build JSON
let mut body = String::new();
response.read_to_string(&mut body).unwrap();
Ok(try!(Json::from_str(&body)))
}
fn parse_all_tasks(reply: &Json) -> Result<Vec<Task>, ParseError> {
let json_to_task = |json: &Json| -> Result<Task, ParseError> {
let page_id: u64 = try!(json.find("pageid")
.and_then(|id| id.as_u64())
.ok_or(ParseError::UnexpectedFormat));
let title: &str = try!(json.find("title")
.and_then(|title| title.as_string())
.ok_or(ParseError::UnexpectedFormat));
Ok(Task {
page_id: page_id,
title: title.to_owned(),
})
};
let tasks_json = try!(reply.find_path(&["query", "categorymembers"])
.and_then(|tasks| tasks.as_array())
.ok_or(ParseError::UnexpectedFormat));
// Convert into own type
tasks_json.iter().map(json_to_task).collect()
}
fn count_number_examples(task: &Json, task_id: u64) -> Result<u32, ParseError> {
let revisions =
try!(task.find_path(&["query", "pages", task_id.to_string().as_str(), "revisions"])
.and_then(|content| content.as_array())
.ok_or(ParseError::UnexpectedFormat));
let content = try!(revisions[0]
.find("*")
.and_then(|content| content.as_string())
.ok_or(ParseError::UnexpectedFormat));
Ok(content.split("=={{header").count() as u32)
}
pub fn query_all_tasks() -> Vec<Task> {
let query = construct_query_category("Programming_Tasks");
let json: Json = query_api(query).unwrap();
parse_all_tasks(&json).unwrap()
}
pub fn query_a_task(task: &Task) -> u32 {
let query = construct_query_task_content(&task.page_id.to_string());
let json: Json = query_api(query).unwrap();
count_number_examples(&json, task.page_id).unwrap()
}
The function is then run using the following:
extern crate count_examples;
fn main() {
let all_tasks = count_examples::query_all_tasks();
for task in &all_tasks {
let count = count_examples::query_a_task(task);
println!("Task: {} has {} examples", task.title, count);
}
}
Scala
import scala.language.postfixOps
object TaskCount extends App {
import java.net.{ URL, URLEncoder }
import scala.io.Source.fromURL
System.setProperty("http.agent", "*")
val allTasksURL =
"http://www.rosettacode.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml"
val allTasks = xml.parsing.XhtmlParser(fromURL(new URL(allTasksURL)))
val regexExpr = "(?i)==\\{\\{header\\|".r
def oneTaskURL(title: String) = {
println(s"Check $title")
"http://www.rosettacode.org/w/index.php?title=%s&action=raw" format URLEncoder.encode(title.replace(' ', '_'), "UTF-8")
}
def count(title: String) = regexExpr findAllIn fromURL(new URL(oneTaskURL(title)))(io.Codec.UTF8).mkString length
val counts = for (task <- allTasks \\ "cm" \\ "@title" map (_.text)) yield scala.actors.Futures.future((task, count(task)))
counts map (_.apply) map Function.tupled("%s: %d examples." format (_, _)) foreach println
println("\nTotal: %d examples." format (counts map (_.apply._2) sum))
}
Sidef
var lwp = require('LWP::UserAgent').new(agent => 'Mozilla/5.0');
var site = 'http://rosettacode.org';
var list_url = '/mw/api.php?action=query&list=categorymembers&'+
'cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml';
var content = lwp.get(site + list_url).decoded_content;
while (var m = content.match(/cm.*?title="(.*?)"/g)) {
(var slug = m[0]).gsub!(' ', '_');
var count = lwp.get("#{site}/wiki/#{slug}").decoded_content.count(/toclevel-1/g);
say "#{m[0]}: #{count} examples";
}
- Output:
100 doors: 278 examples 15 Puzzle Game: 50 examples 15 puzzle solver: 10 examples 2048: 41 examples 24 game: 91 examples 24 game/Solve: 56 examples 4-rings or 4-squares puzzle: 44 examples 9 billion names of God the integer: 48 examples 99 Bottles of Beer: 287 examples A+B: 228 examples ...
Tcl
package require Tcl 8.5
package require http
package require json
fconfigure stdout -buffering none
proc get_tasks {category} {
set start [clock milliseconds]
puts -nonewline "getting $category members..."
set base_url http://www.rosettacode.org/w/api.php
set query {action query list categorymembers cmtitle Category:%s format json cmlimit 500}
set this_query [dict create {*}[split [format $query $category]]]
set tasks [list]
while {1} {
set url [join [list $base_url [http::formatQuery {*}$this_query]] ?]
set response [http::geturl $url]
if {[set s [http::status $response]] ne "ok" || [http::ncode $response] != 200} {
error "Oops: url=$url\nstatus=$s\nhttp code=[http::code $response]"
}
set data [json::json2dict [http::data $response]]
http::cleanup $response
# add tasks to list
foreach task [dict get $data query categorymembers] {
lappend tasks [dict get [dict create {*}$task] title]
}
if {[catch {dict get $data query-continue categorymembers cmcontinue} continue_task] != 0} {
# no more continuations, we're done
break
}
dict set this_query cmcontinue $continue_task
}
puts " found [llength $tasks] tasks in [expr {[clock milliseconds] - $start}] milliseconds"
return $tasks
}
# This proc can be replaced by a single regexp command:
# set count [regexp -all "***=$needle" $haystack]
# However this proc is more efficient -- we're dealing with plain strings only.
proc count_substrings {needle haystack} {
set count 0
set idx 0
while {[set idx [string first $needle $haystack $idx]] != -1} {
incr count
incr idx
}
return $count
}
set total 0
foreach task [get_tasks Programming_Tasks] {
set url [format "http://www.rosettacode.org/w/index.php?title=%s&action=raw" [string map {{ } _} $task]]
set response [http::geturl $url]
if {[set s [http::status $response]] ne "ok" || [http::ncode $response] != 200} {
error "Oops: url=$url\nstatus=$s\nhttp code=[http::code $response]"
}
set count [count_substrings "\{\{header|" [http::data $response]]
puts [format "%3d examples in %s" $count $task]
http::cleanup $response
incr total $count
}
puts "\nTotal: $total examples"
TUSCRIPT
$$ MODE TUSCRIPT
url="http://www.rosettacode.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml"
data=REQUEST (url)
BUILD S_TABLE beg=*
DATA :title=":
BUILD S_TABLE end=*
DATA :":
titles=EXTRACT (data,beg|,end,1,0,"~~")
titles=SPLIT (titles,":~~:")
sz_titles=SIZE (titles)
BUILD R_TABLE header=":==\{\{header|:"
all=*
ERROR/STOP CREATE ("tasks",seq-e,-std-)
COMPILE
LOOP title=titles
ask=*
ask =SET_VALUE(ask,"title",title)
ask =SET_VALUE(ask,"action","raw")
ask =ENCODE (ask,cgi)
http ="http://www.rosettacode.org/mw/index.php"
url =CONCAT (http,"?",ask)
data =REQUEST (url)
header =FILTER_INDEX (data,header,-)
sz_header=SIZE(header)
line =CONCAT (title,"=",sz_header," members")
FILE "tasks" = line
all =APPEND(all,sz_header)
ENDLOOP
ENDCOMPILE
all =JOIN(all),sum=SUM(all),time=time()
line=CONCAT (time,": ", sz_titles, " Programing Tasks: ", sum, " solutions")
FILE "tasks" = line
Output in file "tasks":
100 doors=104 members 24 game=27 members 24 game/Solve=21 members 99 Bottles of Beer=124 members A+B=76 members Abstract type=35 members Accumulator factory=44 members ... XML/Input=39 members XML/Output=32 members XML/XPath=24 members Xiaolin Wu's line algorithm=0 members Y combinator=33 members Yahoo! search interface=10 members Zig-zag matrix=46 members 2011-01-15 03:41:30: 455 Programing Tasks: 16009 solutions
UNIX Shell
Requires the curl and jq command-line utilities.
#!/usr/bin/env bash
SITE=https://www.rosettacode.org
API=$SITE/mw/api.php
PAGES=$SITE/mw/index.php
query="$API?action=query"
query+=$(printf '&%s' \
list=categorymembers \
cmtitle=Category:Programming_Tasks \
cmlimit=500)
total=0
while read title; do
t=${title// /_}
tasks=$(curl -s "$PAGES?title=$t&action=raw" \
| grep -c '{{header|')
printf '%s: %d examples.\n' "$title" "$tasks"
let total+=tasks
done < <(curl -s "$query&format=json" \
| jq -r '.query.categorymembers[].title')
printf '\nTotal: %d examples.\n' "$total"
Wren
An embedded program so we can use the libcurl library.
/* Rosetta_Code_Count_examples.wren */
import "./pattern" for Pattern
var CURLOPT_URL = 10002
var CURLOPT_FOLLOWLOCATION = 52
var CURLOPT_WRITEFUNCTION = 20011
var CURLOPT_WRITEDATA = 10001
foreign class Buffer {
construct new() {} // C will allocate buffer of a suitable size
foreign value // returns buffer contents as a string
}
foreign class Curl {
construct easyInit() {}
foreign easySetOpt(opt, param)
foreign easyPerform()
foreign easyCleanup()
}
var curl = Curl.easyInit()
var getContent = Fn.new { |url|
var buffer = Buffer.new()
curl.easySetOpt(CURLOPT_URL, url)
curl.easySetOpt(CURLOPT_FOLLOWLOCATION, 1)
curl.easySetOpt(CURLOPT_WRITEFUNCTION, 0) // write function to be supplied by C
curl.easySetOpt(CURLOPT_WRITEDATA, buffer)
curl.easyPerform()
return buffer.value
}
var url = "https://www.rosettacode.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml"
var content = getContent.call(url)
var p = Pattern.new("title/=\"[+1^\"]\"")
var matches = p.findAll(content)
for (m in matches) {
var title = m.capsText[0].replace("'", "'").replace(""", "\"")
var title2 = title.replace(" ", "_").replace("+", "\%252B")
var taskUrl = "https://www.rosettacode.org/w/index.php?title=%(title2)&action=raw"
var taskContent = getContent.call(taskUrl)
var lines = taskContent.split("\n")
var count = lines.count { |line| line.trim().startsWith("=={{header|") }
System.print("%(title) : %(count) examples")
}
curl.easyCleanup()
which we now embed in the following C program, build and run.
/* gcc Rosetta_Code_Count_examples.c -o Rosetta_Code_Count_examples -lcurl -lwren -lm */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
#include "wren.h"
struct MemoryStruct {
char *memory;
size_t size;
};
/* C <=> Wren interface functions */
static size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp) {
size_t realsize = size * nmemb;
struct MemoryStruct *mem = (struct MemoryStruct *)userp;
char *ptr = realloc(mem->memory, mem->size + realsize + 1);
if(!ptr) {
/* out of memory! */
printf("not enough memory (realloc returned NULL)\n");
return 0;
}
mem->memory = ptr;
memcpy(&(mem->memory[mem->size]), contents, realsize);
mem->size += realsize;
mem->memory[mem->size] = 0;
return realsize;
}
void C_bufferAllocate(WrenVM* vm) {
struct MemoryStruct *ms = (struct MemoryStruct *)wrenSetSlotNewForeign(vm, 0, 0, sizeof(struct MemoryStruct));
ms->memory = malloc(1);
ms->size = 0;
}
void C_bufferFinalize(void* data) {
struct MemoryStruct *ms = (struct MemoryStruct *)data;
free(ms->memory);
}
void C_curlAllocate(WrenVM* vm) {
CURL** pcurl = (CURL**)wrenSetSlotNewForeign(vm, 0, 0, sizeof(CURL*));
*pcurl = curl_easy_init();
}
void C_value(WrenVM* vm) {
struct MemoryStruct *ms = (struct MemoryStruct *)wrenGetSlotForeign(vm, 0);
wrenSetSlotString(vm, 0, ms->memory);
}
void C_easyPerform(WrenVM* vm) {
CURL* curl = *(CURL**)wrenGetSlotForeign(vm, 0);
curl_easy_perform(curl);
}
void C_easyCleanup(WrenVM* vm) {
CURL* curl = *(CURL**)wrenGetSlotForeign(vm, 0);
curl_easy_cleanup(curl);
}
void C_easySetOpt(WrenVM* vm) {
CURL* curl = *(CURL**)wrenGetSlotForeign(vm, 0);
CURLoption opt = (CURLoption)wrenGetSlotDouble(vm, 1);
if (opt < 10000) {
long lparam = (long)wrenGetSlotDouble(vm, 2);
curl_easy_setopt(curl, opt, lparam);
} else if (opt < 20000) {
if (opt == CURLOPT_WRITEDATA) {
struct MemoryStruct *ms = (struct MemoryStruct *)wrenGetSlotForeign(vm, 2);
curl_easy_setopt(curl, opt, (void *)ms);
} else if (opt == CURLOPT_URL) {
const char *url = wrenGetSlotString(vm, 2);
curl_easy_setopt(curl, opt, url);
}
} else if (opt < 30000) {
if (opt == CURLOPT_WRITEFUNCTION) {
curl_easy_setopt(curl, opt, &WriteMemoryCallback);
}
}
}
WrenForeignClassMethods bindForeignClass(WrenVM* vm, const char* module, const char* className) {
WrenForeignClassMethods methods;
methods.allocate = NULL;
methods.finalize = NULL;
if (strcmp(module, "main") == 0) {
if (strcmp(className, "Buffer") == 0) {
methods.allocate = C_bufferAllocate;
methods.finalize = C_bufferFinalize;
} else if (strcmp(className, "Curl") == 0) {
methods.allocate = C_curlAllocate;
}
}
return methods;
}
WrenForeignMethodFn bindForeignMethod(
WrenVM* vm,
const char* module,
const char* className,
bool isStatic,
const char* signature) {
if (strcmp(module, "main") == 0) {
if (strcmp(className, "Buffer") == 0) {
if (!isStatic && strcmp(signature, "value") == 0) return C_value;
} else if (strcmp(className, "Curl") == 0) {
if (!isStatic && strcmp(signature, "easySetOpt(_,_)") == 0) return C_easySetOpt;
if (!isStatic && strcmp(signature, "easyPerform()") == 0) return C_easyPerform;
if (!isStatic && strcmp(signature, "easyCleanup()") == 0) return C_easyCleanup;
}
}
return NULL;
}
static void writeFn(WrenVM* vm, const char* text) {
printf("%s", text);
}
void errorFn(WrenVM* vm, WrenErrorType errorType, const char* module, const int line, const char* msg) {
switch (errorType) {
case WREN_ERROR_COMPILE:
printf("[%s line %d] [Error] %s\n", module, line, msg);
break;
case WREN_ERROR_STACK_TRACE:
printf("[%s line %d] in %s\n", module, line, msg);
break;
case WREN_ERROR_RUNTIME:
printf("[Runtime Error] %s\n", msg);
break;
}
}
char *readFile(const char *fileName) {
FILE *f = fopen(fileName, "r");
fseek(f, 0, SEEK_END);
long fsize = ftell(f);
rewind(f);
char *script = malloc(fsize + 1);
fread(script, 1, fsize, f);
fclose(f);
script[fsize] = 0;
return script;
}
static void loadModuleComplete(WrenVM* vm, const char* module, WrenLoadModuleResult result) {
if( result.source) free((void*)result.source);
}
WrenLoadModuleResult loadModule(WrenVM* vm, const char* name) {
WrenLoadModuleResult result = {0};
if (strcmp(name, "random") != 0 && strcmp(name, "meta") != 0) {
result.onComplete = loadModuleComplete;
char fullName[strlen(name) + 6];
strcpy(fullName, name);
strcat(fullName, ".wren");
result.source = readFile(fullName);
}
return result;
}
int main(int argc, char **argv) {
WrenConfiguration config;
wrenInitConfiguration(&config);
config.writeFn = &writeFn;
config.errorFn = &errorFn;
config.bindForeignClassFn = &bindForeignClass;
config.bindForeignMethodFn = &bindForeignMethod;
config.loadModuleFn = &loadModule;
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "Rosetta_Code_Count_examples.wren";
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
switch (result) {
case WREN_RESULT_COMPILE_ERROR:
printf("Compile Error!\n");
break;
case WREN_RESULT_RUNTIME_ERROR:
printf("Runtime Error!\n");
break;
case WREN_RESULT_SUCCESS:
break;
}
wrenFreeVM(vm);
free(script);
return 0;
}
- Output:
Just showing the first 25 'full' tasks:
100 doors : 355 examples 100 prisoners : 85 examples 15 puzzle game : 86 examples 15 puzzle solver : 27 examples 2048 : 65 examples 21 game : 52 examples 24 game : 107 examples 24 game/Solve : 64 examples 4-rings or 4-squares puzzle : 74 examples 9 billion names of God the integer : 66 examples 99 bottles of beer : 376 examples A+B : 296 examples Abbreviations, automatic : 58 examples Abbreviations, easy : 50 examples Abbreviations, simple : 46 examples ABC problem : 150 examples Abelian sandpile model : 40 examples Abelian sandpile model/Identity : 28 examples Abstract type : 93 examples Abundant odd numbers : 72 examples Abundant, deficient and perfect number classifications : 110 examples Accumulator factory : 115 examples Achilles numbers : 25 examples Ackermann function : 243 examples Active Directory/Connect : 29 examples ....
zkl
Uses shared libraries YAJL and cURL and handles "continue" responses.
var [const] YAJL=Import("zklYAJL")[0], CURL=Import("zklCurl");
fcn getTasks(language){
continueValue,tasks:="",Data(0,String); // "nm\0nm\0...."
do{
page:=CURL().get(("http://rosettacode.org/mw/api.php?"
"action=query&cmlimit=500"
"&format=json"
"&list=categorymembers"
"&cmtitle=Category:%s"
"&cmcontinue=%s").fmt(language,continueValue));
page=page[0].del(0,page[1]); // get rid of HTML header
json:=YAJL().write(page).close();
json["query"]["categorymembers"].pump(tasks,T("get","title"));
continueValue=json.find("continue") //continue:-||,cmcontinue:page|954|19)
.toList().apply("concat","=").concat("&");
}while(continueValue);
tasks
}
re:=RegExp(0'!\s+==\s*{{\s*header\s*\|!); // == {{ header | zkl
foreach task in (getTasks("Programming_Tasks")){
page:=CURL().get(
"http://www.rosettacode.org/mw/index.php?title=%s&action=raw"
.fmt(CURL.urlEncode(task)));
page=page[0].del(0,page[1]); // get rid of HTML header
cnt,n:=0,0; while(re.search(page,True,n)){ cnt+=1; n=re.matched[0].sum(0); }
"%4d: %s".fmt(cnt,task).println();
}
- Output:
229: 100 doors 15: 15 Puzzle Game ... 257: 99 Bottles of Beer 199: A+B ... 28: Calendar - for "REAL" programmers ... 9: Stream Merge ... 78: Zero to the zero power 19: Zhang-Suen thinning algorithm 83: Zig-zag matrix
- Programming Tasks
- Rosetta Code related
- Ada
- AWS
- AutoHotkey
- BBC BASIC
- Bracmat
- C sharp
- Clojure
- D
- EGL
- Erlang
- Xmerl
- F Sharp
- Factor
- Go
- Haskell
- HTTP XML
- Unicon
- Icon Programming Library
- J
- Java
- Jq
- Julia
- Lasso
- LiveCode
- Maple
- Mathematica
- Wolfram Language
- MATLAB
- Octave
- Nim
- Objeck
- OCaml
- Ocamlnet
- Xml-light
- Oz
- OzHttpClient
- Perl
- Mojolicious
- Phix
- PicoLisp
- PureBasic
- Python
- Requests
- R
- XML (R)
- RCurl
- Racket
- Raku
- Ring
- Ruby
- REXML
- Run BASIC
- Rust
- Scala
- Sidef
- Tcl
- Tcllib
- TUSCRIPT
- UNIX Shell
- Wren
- Libcurl
- Wren-pattern
- Zkl
- Batch File/Omit
- Brainf***/Omit
- Brlcad/Omit
- GUISS/Omit
- Lilypond/Omit
- Maxima/Omit
- Openscad/Omit
- PostScript/Omit
- TI-83 BASIC/Omit
- TI-89 BASIC/Omit
- Yorick/Omit
- ZX Spectrum Basic/Omit