Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
16
Task/Hailstone-sequence/Jq/hailstone-sequence-1.jq
Normal file
16
Task/Hailstone-sequence/Jq/hailstone-sequence-1.jq
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# Generate the hailstone sequence as a stream to save space (and time) when counting
|
||||
def hailstone:
|
||||
recurse( if . > 1 then
|
||||
if . % 2 == 0 then ./2|floor else 3*. + 1 end
|
||||
else empty
|
||||
end );
|
||||
|
||||
def count(g): reduce g as $i (0; .+1);
|
||||
|
||||
# return [i, length] for the first maximal-length hailstone sequence where i is in [1 .. n]
|
||||
def max_hailstone(n):
|
||||
# state: [i, length]
|
||||
reduce range(1; n+1) as $i
|
||||
([0,0];
|
||||
($i | count(hailstone)) as $l
|
||||
| if $l > .[1] then [$i, $l] else . end);
|
||||
7
Task/Hailstone-sequence/Jq/hailstone-sequence-2.jq
Normal file
7
Task/Hailstone-sequence/Jq/hailstone-sequence-2.jq
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
[27|hailstone] as $h
|
||||
| "[27|hailstone]|length is \($h|length)",
|
||||
"The first four numbers: \($h[0:4])",
|
||||
"The last four numbers: \($h|.[length-4:length])",
|
||||
"",
|
||||
max_hailstone(100000) as $m
|
||||
| "Maximum length for n|hailstone for n in 1..100000 is \($m[1]) (n == \($m[0]))"
|
||||
6
Task/Hailstone-sequence/Jq/hailstone-sequence-3.jq
Normal file
6
Task/Hailstone-sequence/Jq/hailstone-sequence-3.jq
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
$ jq -M -r -n -f hailstone.jq
|
||||
[27|hailstone]|length is 112
|
||||
The first four numbers: [27,82,41,124]
|
||||
The last four numbers: [8,4,2,1]
|
||||
|
||||
Maximum length for n|hailstone for n in 1..100000 is 351 (n == 77031)
|
||||
Loading…
Add table
Add a link
Reference in a new issue