Skip to content

Instantly share code, notes, and snippets.

@jakedobkin
Created December 28, 2011 00:10
Show Gist options
  • Select an option

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

Select an option

Save jakedobkin/1525536 to your computer and use it in GitHub Desktop.
Euler 80
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