Problem 57

completed December 25, 2011

Comments

This one was really fun. At first I set up a function that would handle the iterations as rational numbers. Then I had to rewrite it to handle in and outputs as fractions. The switch was pretty simple, and once it happened, the correct answer came quickly.

Code

def iterant(x):
	return ((2*x[1] + x[0]), (x[1] + x[0]))

def digits(n):
	n = str(n)
	length = 0
	for i in n:
		length += 1
	return length

x = [1, 1]
count = 0
for n in range(1000):
	x = iterant(x)
	if digits(x[0]) > digits(x[1]):
		print x
		count += 1
		
print count