Problem 92

completed December 24, 2011

Comments

I couldn’t think of a way to get this to run any faster. So I just sat and waited. I probably tried longer to get it to run faster than the time it would have taken had I just sat and waited. But they do say that these should be able to complete in under a minute, and I am quite impatient.

Code

def square(n):
	number = str(n)
	sum = 0
	for i in number:
		sum += int(i)**2
	return sum

eighty_nines = 0
eightset = [89]
oneset = [1]

for m in range(1, 10000000):
	if m%10**5 == 0: print m/10**5
	n = m
	a = True
	while a == True:
		if n == 89:
			a = False
			eighty_nines += 1
		elif n == 1:
			a = False
		else:
			n = square(n)
			
print eighty_nines