Skip to content

Instantly share code, notes, and snippets.

@ziotom78
Created September 28, 2011 10:05
Show Gist options
  • Save ziotom78/1247545 to your computer and use it in GitHub Desktop.
Save ziotom78/1247545 to your computer and use it in GitHub Desktop.
Solution of Project Euler's problem 34 (Python)
def fact (n):
"Return n!."
if n < 2:
return 1
else:
result = 1
for i in xrange (2, n + 1):
result = result * i
return result
fast_fact = {}
def compute_fast_fact ():
"Initialize `fast_fact'."
for n in xrange (0, 10):
fast_fact[n] = fact (n)
def digits (n):
return [int(x) for x in list (str (n))]
def test_number (n):
return n == sum ([fast_fact[digit] for digit in digits (n)])
def solution (max_n):
return sum ([num for num in xrange (10, max_n) if test_number(num)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment