/ Published in: Python
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!/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)