Something totally math geeky. I saw something a couple of months ago about the Fibonacci series being encoded in the decimal expansion of 1/89:
1/89 = sum( k = 0 to infinity, .1^k * Fib(k) ) where Fib(0) = 0, Fib(1) = 1, and Fib(n) = Fib(n-1) + Fib(n-2).
But it hit me yesterday that since 1/89 is a rational number, it repeats. So I wrote a python program to show it:
from sys import argv
def divide( numerator, denominator, maxlen ):
if numerator == 0:
return “0”
result = “”
if numerator > denominator:
result = str( numerator // denominator )
numerator = numerator % denominator
if numerator == 0 or len( result ) >= maxlen:
return result
result += “.”
while ( numerator != 0 ) and ( len( result ) < maxlen ):
numerator *= 10
if numerator < denominator:
result += “0”
else:
d = numerator // denominator
numerator = numerator % denominator
result += str( d )
return result
def compute_fibs( count, offset = ” ” ):
n1 = 0
n2 = 1
tot = 0
res = “”
for ct in range( count ):
sn1 = str( n1 )
res += offset + ” ” * max( 0, ct + 1 - len( sn1 ) ) + sn1 + “n”
tot = tot * 10 + n1
temp = n2
n2 = n1 + n2
n1 = temp
return res, offset + ” ” + str( tot )
if __name__ == “__main__”:
le = int( argv[ 1 ] )
res, tot = compute_fibs( le )
print( res )
print( tot )
print( divide( 1, 89, le ) )
If you run the code and pass a length, it prints out three things:
1. The first set are the length Fibonacci numbers shifted as if they are being added as in the equation above, though I leave off the zeroes due to shifting.
2. The sum of these numbers.
3. The computation of 1/89 to the input length.
1/89 repeats every 44 digits. If you set the length to about 115, you will see the repeating happening twice in the sum (the last so many digits won’t match because you would need to pull in more Fibonacci numbers).
It’s just neat that that kind of embedding occurs in the numbers, especially because the repeating pattern isn’t caused by numbers that show the repetition themselves.