Created
September 28, 2011 10:05
-
-
Save ziotom78/1247545 to your computer and use it in GitHub Desktop.
Solution of Project Euler's problem 34 (Python)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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