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,8 @@
def permutations:
if length == 0 then []
else
. as $in
| range(0;length) as $i
| ($in|del(.[$i])|permutations)
| [$in[$i]] + .
end ;

View file

@ -0,0 +1,10 @@
def sorted:
def until(cond; next):
def _until: if cond then . else (next|_until) end;
_until;
length as $length
| if $length <= 1 then true
else . as $in
| 1 | until( . == $length or $in[.-1] > $in[.] ; .+1) == $length
end;

View file

@ -0,0 +1,2 @@
def permutation_sort_slow:
reduce permutations as $p (null; if . then . elif ($p | sorted) then $p else . end);

View file

@ -0,0 +1,9 @@
def permutation_sort:
# emit the first item in stream that satisfies the condition
def first(stream; cond):
label $out
| foreach stream as $item
( [false, null];
if .[0] then break $out else [($item | cond), $item] end;
if .[0] then .[1] else empty end );
first(permutations; sorted);

View file

@ -0,0 +1 @@
["too", true, 1, 0, {"a":1}, {"a":0} ] | permutation_sort

View file

@ -0,0 +1,2 @@
$ jq -c -n -f Permutation_sort.jq
[true,0,1,"too",{"a":0},{"a":1}]