Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,34 @@
|
|||
def hailstone(n)
|
||||
seq = list()
|
||||
|
||||
while (n > 1)
|
||||
append seq n
|
||||
if (n % 2)=0
|
||||
n = int(n / 2)
|
||||
else
|
||||
n = int((3 * n) + 1)
|
||||
end
|
||||
end
|
||||
append seq n
|
||||
return seq
|
||||
end
|
||||
|
||||
if main
|
||||
h = hailstone(27)
|
||||
println "hailstone(27)"
|
||||
println "total elements: " + len(hailstone(27))
|
||||
print h[0] + ", " + h[1] + ", " + h[2] + ", " + h[3] + ", ..., "
|
||||
println h[-4] + ", " + h[-3] + ", " + h[-2] + ", " + h[-1]
|
||||
|
||||
max = 0
|
||||
maxLoc = 0
|
||||
for i in range(1,99999)
|
||||
result = len(hailstone(i))
|
||||
if (result > max)
|
||||
max = result
|
||||
maxLoc = i
|
||||
end
|
||||
end
|
||||
print "\nThe number less than 100,000 with the longest sequence is "
|
||||
println maxLoc + " with a length of " + max
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue