Solve problem 80 in Python with cheating.
This commit is contained in:
@@ -1,8 +1,20 @@
|
||||
from decimal import *
|
||||
|
||||
|
||||
def euler_080():
|
||||
return 0
|
||||
# XXX: totally cheated by using decimal library.
|
||||
def strsum(s):
|
||||
return sum(map(int, s))
|
||||
|
||||
getcontext().prec = 200
|
||||
r = 0
|
||||
for n in range(1, 101):
|
||||
b = str(Decimal(n).sqrt()).replace(".", "")[:100]
|
||||
if len(b) == 100:
|
||||
r += strsum(b)
|
||||
return r
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("e080.py: " + str(euler_080()))
|
||||
assert(euler_080() == 0)
|
||||
assert(euler_080() == 40886)
|
||||
|
||||
Reference in New Issue
Block a user