Euler Problem 80


Python rocks. No surprise here. Its got a Decimal module that does everything. This routine runs inside of a second.

#Euler80
import decimal
from math import sqrt, floor
class Problem80:
    def __init__(self):
        pass
    def Solution(self):
        count = 0
        decimal.getcontext().prec = 110
        for n in range (1, 101):
            num = int(floor(sqrt(n)))
            text = str(decimal.Decimal(n).sqrt())[2:102]
            if len(text) == 100:
                count += num
                for i in range (0,99):
                    count += int(text[i])
            print n,count
        return "Answer = " + str(count)
if __name__ == '__main__':
    P = Problem80()
    print P.Solution()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s