Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,17 @@
def stoogesort:
def swap(i;j): .[i] as $t | .[i] = .[j] | .[j] = $t;
# for efficiency, define an auxiliary function
# that takes as input [L, i, j]
def ss: .[1] as $i | .[2] as $j
| .[0]
| if .[$j] < .[$i] then swap($i;$j) else . end
| if $j - $i > 1 then
(($j - $i + 1) / 3 | floor) as $t
| [., $i, $j-$t] | ss
| [., $i+$t, $j] | ss
| [., $i, $j-$t] | ss
else .
end;
[., 0, length-1] | ss;

View file

@ -0,0 +1,6 @@
([],
[1],
[1,2],
[1,3,2,4],
[1,4,5,3,-6,3,7,10,-2,-5]
) | stoogesort

View file

@ -0,0 +1,6 @@
$ jq -c -n -f stooge_sort.jq
[]
[1]
[1,2]
[1,2,3,4]
[-6,-5,-2,1,3,3,4,5,7,10]