Created
November 16, 2011 23:30
-
-
Save jakedobkin/1371865 to your computer and use it in GitHub Desktop.
Euler 16 in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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