September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -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;
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
([],
|
||||
[1],
|
||||
[1,2],
|
||||
[1,3,2,4],
|
||||
[1,4,5,3,-6,3,7,10,-2,-5]
|
||||
) | stoogesort
|
||||
|
|
@ -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]
|
||||
Loading…
Add table
Add a link
Reference in a new issue