Euler 34

El problema 34 del proyecto Euler dice lo siguiente:

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.

Me pareció que podía ser divertido hacer algo en Python para resolverlo y he aquí el resultado:

import math
def igual_fact(num):

suma = 0

for i in str(num):

suma += math.factorial(int(i))

if suma == num:

return True

else:

return False

suma = 0
for i in range(1,3*10**6):

if igual_fact(i):
suma += i

print(suma – 3)

 

Aquí tenéis el enlace: https://repl.it/IUPV/1

Por cierto, el resultado es: 40730


 
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s