You should find that converting longs to strings (say, for printing them)
is *very* slow. E.g. the following code
big = 10L**100 # one google, a big number
while True:
print big # so we can see the last value before it fails
big *= 10
will run terribly slow and should be written as:
big = 10L**100 # one google, a big number
try:
while True:
big *= 10
except: # don't know what exception will be raised, so catch ANYTHING
print len(str(big))-1 # the number of digits
only does the slow conversion to string once, instead of every time around
the loop. However, once your machine starts paging, it will still slow
down a lot.
Yes, longs are limited only by the amount of memory accessible.
But there may be other limitations even if you have the memory.
For example, this test is limited to generation 10
because tne 11th generation produces "outrageous
exponent" error. Here, every 9th 1st generation,
starting from the fifth is a second generation, every
9th sencond, starting from the fifth, is a 3rd generation,
every 9th 3rd gen, starting from the 5th is a 4th gen, etc.
Closed form: Type12MH(k,i)
Find ith, kth Generation Type [1,2] Mersenne Hailstone
using the closed form equation
2**(6*((i-1)*9**(k-1)+(9**(k-1)-1)/2+1)-1)-1
2**5-1 generation: 1
2**29-1 generation: 2
2**245-1 generation: 3
2**2189-1 generation: 4
2**19685-1 generation: 5
2**177149-1 generation: 6
2**1594325-1 generation: 7
2**14348909-1 generation: 8
2**129140165-1 generation: 9
2**1162261469-1 generation:10
1.797 seconds
There is never a number too large to worry about.