2017-06-11

Project Euler Problem 9

Hola!

Another day, another problem. What's new in this solution is the built-in function is_integer() which I use to check if a float number has no decimal value. For example when c = 5.0, c.is_integer() returns true and when c = 8.3, c.is_integer() returns false. It was a good help since most square roots aren't integers.

product = 1c = 0
for a in range(1, 1000):
    for b in range(1, 1000):
        c2 = a ** 2 + b ** 2        c = c2 ** 0.5        abcSum = a + b + c
        if c.is_integer() and abcSum == 1000:
            c = int(c)
            print("a: ", a, "b: ", b, "c:", c, "sum", abcSum)
            product = a * b * c
            break    if abcSum == 1000:
        break
print("product:", product)



/Ludvig

No comments:

Post a Comment