Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
9
Task/Fusc-sequence/Jq/fusc-sequence-1.jq
Normal file
9
Task/Fusc-sequence/Jq/fusc-sequence-1.jq
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# input should be a non-negative integer
|
||||
def commatize:
|
||||
# "," is 44
|
||||
def digits: tostring | explode | reverse;
|
||||
[foreach digits[] as $d (-1; .+1;
|
||||
(select(. > 0 and . % 3 == 0)|44), $d)]
|
||||
| reverse | implode ;
|
||||
|
||||
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;
|
||||
34
Task/Fusc-sequence/Jq/fusc-sequence-2.jq
Normal file
34
Task/Fusc-sequence/Jq/fusc-sequence-2.jq
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# Save space by truncating the beginning of the array
|
||||
def fusc:
|
||||
0, 1,
|
||||
foreach range(2; infinite) as $n ([0, 1];
|
||||
($n % 2 == 0) as $even
|
||||
| if $even then . + [.[1]] else.[1:] + [.[1] + .[2]] end;
|
||||
.[-1] );
|
||||
|
||||
# Report first longest
|
||||
def fusc( $mx ):
|
||||
def l: commatize|lpad(10);
|
||||
|
||||
foreach limit( $mx; fusc ) as $f ({ maxLen: 0, n: 0 };
|
||||
.emit = false
|
||||
| ("\($f)"|length) as $len
|
||||
| if $len > .maxLen
|
||||
then .maxLen = $len
|
||||
| .emit = "\(.n|l) \($f|commatize)"
|
||||
else .
|
||||
end
|
||||
| .n += 1
|
||||
;
|
||||
select(.emit).emit
|
||||
);
|
||||
|
||||
# First $first numbers in the fusc sequence
|
||||
61 as $first
|
||||
| 2e6 as $mx
|
||||
| "The first \($first) numbers in the fusc sequence are:",
|
||||
([limit($first; fusc)]| map(tostring) | join(" ")) ,
|
||||
|
||||
"\nFirst terms longer than any previous ones for indices < \($mx + 0 |commatize):",
|
||||
" Index Value",
|
||||
fusc($mx)
|
||||
Loading…
Add table
Add a link
Reference in a new issue