2017-06-18

Project Euler Problem 16

Easiest to far. I take the number, make it into a string, during for-loop through the characters in the string, I make them into integers and add them to tot.








number = 2 ** 1000tot = 0
for x in range(0, len(str(number))):
    digit = str(number)[x:x + 1]
    tot += int(digit)

print("tot:", tot)


A slimmer version of the same code:


tot = 0
for x in range(0, len(str(2 ** 1000))): tot += int(str(2 ** 1000)[x:x + 1])

print("tot:", tot)


/Ludvig

No comments:

Post a Comment