Skip to main content

Posts

Showing posts with the label problem9

Problem 9 Project euler solution with python

Special Pythagorean triplet A Pythagorean triplet is a set of three natural numbers, a < b < c , for which, a 2 + b 2 = c 2 For example, 3 2 + 4 2 = 9 + 16 = 25 = 5 2 . There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc . This problem might seem easy to solve, but there is a hidden twist which one might miss. Some of you might have used three for loops to create numbers a , b,c and then check sum of the three is equal to 1000 after which you might have checked the Pythagorean triplet condition given in the question. But you should not do this. One of the best way is to generate two numbers a,b and generate the third number with the condition c = a-b . This will reduce 1000's of extra iterations. An another approach might be to stop the looping once you have found out the solution, because it is given in the question that there is only one such solution. I have used the last approach(Stop after result is found...