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,14 @@
def bubble_sort:
def swap(i;j): .[i] as $x | .[i]=.[j] | .[j]=$x;
# input/output: [changed, list]
reduce range(0; length) as $i
( [false, .];
if $i > 0 and (.[0]|not) then .
else reduce range(0; (.[1]|length) - $i - 1) as $j
(.[0] = false;
.[1] as $list
| if $list[$j] > $list[$j + 1] then [true, ($list|swap($j; $j+1))]
else .
end )
end ) | .[1] ;

View file

@ -0,0 +1,5 @@
(
[3,2,1],
[1,2,3],
["G", "F", "C", "A", "B", "E", "D"]
) | bubble_sort

View file

@ -0,0 +1,4 @@
$ jq -c -n -f Bubble_sort.jq
[1,2,3]
[1,2,3]
["A","B","C","D","E","F","G"]