September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -0,0 +1,15 @@
def countingSort(min; max):
. as $in
| reduce range(0;length) as $i
( {};
($in[$i]|tostring) as $s | .[$s] += 1 # courtesy of the fact that in jq, (null+1) is 1
)
| . as $hash
# now construct the answer:
| reduce range(min; max+1) as $i
( [];
($i|tostring) as $s
| if $hash[$s] == null then .
else reduce range(0; $hash[$s]) as $j (.; . + [$i])
end
);

View file

@ -0,0 +1 @@
[1,2,1,4,0,10] | countingSort(0;10)

View file

@ -0,0 +1,2 @@
$ jq -M -c -n -f counting_sort.jq
[0,1,1,2,4,10]