Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
3
Task/Kolakoski-sequence/Jq/kolakoski-sequence-1.jq
Normal file
3
Task/Kolakoski-sequence/Jq/kolakoski-sequence-1.jq
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
def cycle:
|
||||
def c: .[], c;
|
||||
c;
|
||||
27
Task/Kolakoski-sequence/Jq/kolakoski-sequence-2.jq
Normal file
27
Task/Kolakoski-sequence/Jq/kolakoski-sequence-2.jq
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
# Input: an array
|
||||
# Output: the corresponding kolakoski sequence.
|
||||
# This version of the kolakoski generator is optimized to the extent
|
||||
# that it avoids storing the full sequence by removing the first item
|
||||
# in the .s array at each iteration.
|
||||
def kolakoski:
|
||||
foreach cycle as $next ( {s: []};
|
||||
# ensure the next element occurs .s[0] times
|
||||
.s += [$next]
|
||||
| .extra = [range(0; .s[0]-1) as $i | $next]
|
||||
| .s = .s[1:] + .extra
|
||||
;
|
||||
$next, .extra[] ) ;
|
||||
|
||||
def kolakoski($len): limit($len; kolakoski);
|
||||
|
||||
def iskolakoski:
|
||||
def rle:
|
||||
. as $seq
|
||||
| reduce range(1;length) as $i ({rle:[], count:1};
|
||||
if $seq[$i] == $seq[$i - 1]
|
||||
then .count += 1
|
||||
else .rle = .rle + [.count]
|
||||
| .count = 1
|
||||
end)
|
||||
| .rle;
|
||||
rle | . == .[0 : length] ;
|
||||
6
Task/Kolakoski-sequence/Jq/kolakoski-sequence-3.jq
Normal file
6
Task/Kolakoski-sequence/Jq/kolakoski-sequence-3.jq
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
def tests: [[[1, 2], 20], [[2, 1] ,20], [[1, 3, 1, 2], 30], [[1, 3, 2, 1], 30]];
|
||||
|
||||
tests[] as [$a, $n]
|
||||
| $a
|
||||
| [kolakoski($n)] as $k
|
||||
| "First \($n) of kolakoski sequence for \($a):", $k, "check: \($k | if iskolakoski then "✓" else "❌" end )", ""
|
||||
Loading…
Add table
Add a link
Reference in a new issue