Problem 74

completed January 9, 2012

Comments

I was so relieved when this one worked on the first run. This problems are really starting to get tough!

Code

from math import factorial
def factorialdigits(n):
	total = 0
	for d in str(n):
		total += factorial(int(d))
	return total

n = 0
count = 0

while n < 10**6:
	n += 1
	if n%10000 == 0: print n
	loop = [n]
	next = factorialdigits(n)
	while next not in loop:
		loop.append(next)
		next = factorialdigits(next)
	if len(loop) == 60:
		count += 1

print count