Skip to content

Instantly share code, notes, and snippets.

@jakedobkin
Created November 16, 2011 23:30
Show Gist options
  • Select an option

  • Save jakedobkin/1371865 to your computer and use it in GitHub Desktop.

Select an option

Save jakedobkin/1371865 to your computer and use it in GitHub Desktop.
Euler 16 in Python
# let's try to do problem 16 in python
# first, we need to do some python math
# apparently the ** is exponent in python
answer = str(2**1000)
# now we need to extract each position from this string, convert it back to a number, and add
i=0
sum=0
while (i < len(answer)):
x = answer[i:i+1]
x = int(x)
sum = sum + x
i = i+1
print "2 to the 1000th power is %s" % sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment