Return to Snippet

Revision: 27073
at May 21, 2010 10:38 by chroto


Initial Code
#!/usr/bin/python

# Project Euler - Problem 9

print "\nProject Euler - Problem 9"
print "Find the Pythagorean triplet (a^2 + b^2 = c^2)"
print "where a+b+c = 1000"

hasResult = False

for a in range(1,994):
    b = a + 1
    c = b + 1
    while (a+b+c) < 1000:
        b = b + 1
        c = b + 1 # c is always greater than b
        while (a+b+c) < 1000:
            c = c + 1
        if (c*c) == (a*a) + (b*b):
            hasResult = True
        else:
            c = b+1
    if hasResult:
        break
        
print "result: " + str(a*b*c)

Initial URL


Initial Description


Initial Title
Project Euler - Problem 9

Initial Tags


Initial Language
Python