Created
December 28, 2011 00:10
-
-
Save jakedobkin/1525536 to your computer and use it in GitHub Desktop.
Euler 80
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
| from math import sqrt | |
| from decimal import * | |
| # you need more than 100 digits, b/c otherwise you get rounding errors | |
| getcontext().prec = 105 | |
| squares=[] | |
| for a in range (2,10): | |
| squares.append(a**2) | |
| total=0 | |
| for z in range (2,100): | |
| if z not in squares: | |
| # this ridiculousness is how you force it to decimalize sqrts | |
| x=str(Decimal(str(z))**Decimal(str(0.5))) | |
| # print z,len(x),x, | |
| sum = 0 | |
| for a in range (0,101): | |
| digit = x[a:a+1] | |
| if digit !=".": | |
| sum = sum + int(digit) | |
| # print sum | |
| total+=sum | |
| print total |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment