星期四, 六月 25, 2009

第一个one-liner的程序

不得不说,python真是太强大了。

Euler Problem 16

2^(15) = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.

What is the sum of the digits of the number 2^(1000)?

Solution:
print sum(int(i) for i in str( 2 ** 1000 ))

没有评论: