Anonymous user
Hailstone sequence: Difference between revisions
m
→Cached version
imported>Chinhouse |
imported>Chinhouse m (→Cached version) |
||
Line 6,730:
n = n /2
end if
items.push
end while
cache[origNum] = {"len": items.len,"items":items}
Line 6,736:
getLen = function(n)
if not cache.hasIndex(n) then calc
if n == 1 then return 1
return cache[n].len + getLen(cache[n].items[-1]) - 1
Line 6,742:
getSequence = function(n)
if not cache.hasIndex(n) then calc
if n == 1 then return [1]
return cache[n].items[:-1] + getSequence(cache[n].items[-1])
Line 6,752:
print "and ending with"
print h[-4:]
longSeq = 0
Line 6,764 ⟶ 6,762:
end if
end for
print "The number < 100,000 which has the longest hailstone sequence is " + longSeqVal + "."
print "This sequence has " + longSeq + " elements."
</syntaxhighlight>
|