Posts Tagged ‘prob20’

Problem 20 – One More Line

July 17, 2009

I love one-liners. The sum of the digits of n factorial:

print sum(map(int, str(reduce(lambda x,y:x*y,xrange(1,n+1),1))))

This problem is pretty similar to Problem 16, which I also wrote about. There are probably improvements to be made. Like, you might as well start the xrange at 2, instead of 1. I can’t think of a solution that would be faster to code though.