September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -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
|
||||
);
|
||||
|
|
@ -0,0 +1 @@
|
|||
[1,2,1,4,0,10] | countingSort(0;10)
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
$ jq -M -c -n -f counting_sort.jq
|
||||
[0,1,1,2,4,10]
|
||||
Loading…
Add table
Add a link
Reference in a new issue