23 de julio de 2012

Project Euler 20


#!/usr/bin/env python
from operator import mul
def factorial(n):
    return reduce(mul,range(1,n+1))

#convert n to array of digits
def todig(n): 
    return map(int,str(n))

print sum(todig(factorial(100)))

#this one liner is equivalent:
#sum(map(int,str(reduce(mul,range(1,101)))))