Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
30
Task/Executable-library/Io/executable-library-1.io
Normal file
30
Task/Executable-library/Io/executable-library-1.io
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
HailStone := Object clone
|
||||
HailStone sequence := method(n,
|
||||
if(n < 1, Exception raise("hailstone: expect n >= 1 not #{n}" interpolate))
|
||||
n = n floor // make sure integer value
|
||||
stones := list(n)
|
||||
while (n != 1,
|
||||
n = if(n isEven, n/2, 3*n + 1)
|
||||
stones append(n)
|
||||
)
|
||||
stones
|
||||
)
|
||||
|
||||
if( isLaunchScript,
|
||||
out := HailStone sequence(27)
|
||||
writeln("hailstone(27) has length ",out size,": ",
|
||||
out slice(0,4) join(" ")," ... ",out slice(-4) join(" "))
|
||||
|
||||
maxSize := 0
|
||||
maxN := 0
|
||||
for(n, 1, 100000-1,
|
||||
out = HailStone sequence(n)
|
||||
if(out size > maxSize,
|
||||
maxSize = out size
|
||||
maxN = n
|
||||
)
|
||||
)
|
||||
|
||||
writeln("For numbers < 100,000, ", maxN,
|
||||
" has the longest sequence of ", maxSize, " elements.")
|
||||
)
|
||||
20
Task/Executable-library/Io/executable-library-2.io
Normal file
20
Task/Executable-library/Io/executable-library-2.io
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
counts := Map clone
|
||||
for(n, 1, 100000-1,
|
||||
out := HailStone sequence(n)
|
||||
key := out size asCharacter
|
||||
counts atPut(key, counts atIfAbsentPut(key, 0) + 1)
|
||||
)
|
||||
|
||||
maxCount := counts values max
|
||||
lengths := list()
|
||||
counts foreach(k,v,
|
||||
if(v == maxCount, lengths append(k at(0)))
|
||||
)
|
||||
|
||||
if(lengths size == 1,
|
||||
writeln("The most frequent sequence length for n < 100,000 is ",lengths at(0),
|
||||
" occurring ",maxCount," times.")
|
||||
,
|
||||
writeln("The most frequent sequence lengths for n < 100,000 are:\n",
|
||||
lengths join(",")," occurring ",maxCount," times each.")
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue