Python Implementation of Problem 34
View source code here on GitHub!
Includes
Problem Solution
Project Euler Problem 34
This ended up being a filtering problem. The problem with my solution is that I am not satisfied with my filter at all. I feel like there is a more efficient way to go about it.
Problem:
145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.
Find the sum of all numbers which are equal to the sum of the factorial of their digits.
Note: as 1! = 1 and 2! = 2 are not sums they are not included.
1"""
2Project Euler Problem 34
3
4This ended up being a filtering problem. The problem with my solution is that I
5am not satisfied with my filter at all. I feel like there is a more efficient
6way to go about it.
7
8Problem:
9
10145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.
11
12Find the sum of all numbers which are equal to the sum of the factorial of
13their digits.
14
15Note: as 1! = 1 and 2! = 2 are not sums they are not included.
16"""
17from math import factorial
18
19
20def main() -> int:
21 answer = 0
22 for x in range(10, 100000):
23 if sum(factorial(int(y)) for y in repr(x)) == x:
24 answer += x
25 return answer