Daniele Fucini dfb13c083b
Add comments
Added comments to the python code for the first 25 problems
2019-09-26 13:41:22 +02:00

30 lines
611 B
Python

#!/usr/bin/python3
# 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?
from timeit import default_timer
def main():
start = default_timer()
# Simply calculate 2^1000, convert the result to string and calculate
# the sum of the digits
res = str(2 ** 1000)
sum_ = 0
for i in res:
sum_ = sum_ + int(i)
end = default_timer()
print('Project Euler, Problem 16')
print('Answer: {}'.format(sum_))
print('Elapsed time: {:.9f} seconds'.format(end - start))
if __name__ == '__main__':
main()