22 lines
537 B
Text
22 lines
537 B
Text
sequence Q = {1,1}
|
|
|
|
function q(integer n)
|
|
integer l = length(Q)
|
|
while n>l do
|
|
l += 1
|
|
Q &= Q[l-Q[l-1]]+Q[l-Q[l-2]]
|
|
end while
|
|
return Q[n]
|
|
end function
|
|
|
|
{} = q(10) -- (or collect one by one)
|
|
printf(1,"First ten terms: %s\n",{sprint(Q[1..10])})
|
|
printf(1,"1000th: %d\n",q(1000))
|
|
printf(1,"100,000th: %d\n",q(100_000))
|
|
integer n = 0
|
|
for i=2 to 100_000 do
|
|
n += Q[i]<Q[i-1]
|
|
end for
|
|
printf(1,"Flips up to 100,000: %d\n",{n})
|
|
atom t0 = time()
|
|
printf(1,"100,000,000th: %d (%3.2fs)\n",{q(100_000_000),time()-t0})
|