Project Euler

Problem 34: Digit factorials

Find the sum of all numbers which are equal to the sum of the factorial of their digits. Run this solution at repl.io here.

      
        def factorial(n):
          fac = 1
          for k in range(1, n + 1):
            fac *= k
          return fac

        curious = []

        # just guess an upper bound
        for k in range(3, 100000):
          digits_of_k = [int(i) for i in str(k)]
          if k == sum([factorial(j) for j in digits_of_k]):
            curious.append(k)

        print(sum(curious))
      
    

back to code menu