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,22 @@
def pancakeSort:
def flip(i):
. as $in | ($in[0:i+1]|reverse) + $in[i+1:] ;
# If input is [] then return null
def index_of_max:
. as $in
| reduce range(1; length) as $i
# state: [ix, max]
( [ 0, $in[0] ];
if $in[$i] > .[1] then [ $i, $in[$i] ] else . end )
| .[0] ;
reduce range(0; length) as $iup
(.;
(length - $iup - 1) as $i
| (.[0:$i+1] | index_of_max) as $max
# flip about $max and then about $i unless $i == $max
| if ($i == $max) then .
else flip($max) | flip($i)
end ) ;

View file

@ -0,0 +1,2 @@
[range(0;2), null, 1.0, 0.5, [1], [2], {"b":1}, {"a":2}, range(2;4)]
| pancakeSort

View file

@ -0,0 +1,2 @@
$ jq -M -c -n -f pancake_sort.jq
[null,0,0.5,1,1,2,3,[1],[2],{"a":2},{"b":1}]