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 quicksort(cmp):
if length < 2 then . # it is already sorted
else .[0] as $pivot
| reduce .[] as $x
# state: [less, equal, greater]
( [ [], [], [] ]; # three empty arrays:
if $x == $pivot then .[1] += [$x] # add x to equal
else ([$x,$pivot]|cmp) as $order
| if $order == 0 then .[1] += [$x] # ditto
elif ($order|type) == "number" then
if $order < 0 then .[0] += [$x] # add x to less
else .[2] += [$x] # add x to greater
end
else ([$pivot,$x]|cmp) as $order2
| if $order and $order2 then .[1] += [$x] # add x to equal
elif $order then .[0] += [$x] # add x to less
else .[2] += [$x] # add x to greater
end
end
end )
| (.[0] | quicksort(cmp) ) + .[1] + (.[2] | quicksort(cmp) )
end ;

View file

@ -0,0 +1,3 @@
# Sort by string length, breaking ties using ordinary string comparison.
["z", "yz", "ab", "c"]
| quicksort( (.[0]|length) > (.[1]|length) or ( (.[0]|length) == (.[1]|length) and .[0] < .[1] ) )

View file

@ -0,0 +1,6 @@
[
"ab",
"yz",
"c",
"z"
]