Rosetta Code/Count examples: Difference between revisions

jq
No edit summary
(jq)
Line 1,167:
 
 
 
=={{header|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`.
 
<lang bash>#!/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.</lang>
 
{{out}}
 
<pre>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.</pre>
 
=={{header|Lasso}}==
2,497

edits