This is our solution and implementation to problem #75 on Project Euler.
Note: the code and contents here might be slightly different than what is in the video. We've made some improvements to some of the code since recording.
If you would like to view the original problem and solve it, please visit: Singular Integer Right Triangles on Project Euler. If you're having trouble solving this problem, or are just curious to see how others have solved it, feel free to take a look, but please put solid effort into solving this before viewing the actual solution to the problem.
It turns out that 12 cm is the smallest length of wire that can be bent to form an integer sided right angle triangle in exactly one way, but there are many more examples.
12 cm: (3,4,5)
24 cm: (6,8,10)
30 cm: (5,12,13)
36 cm: (9,12,15)
40 cm: (8,15,17)
48 cm: (12,16,20)
In contrast, some lengths of wire, like 20 cm, cannot be bent to form an integer sided right angle triangle, and other lengths allow more than one solution to be found; for example, using 120 cm it is possible to form exactly three different integer sided right angle triangles.
120 cm: (30,40,50), (20,48,52), (24,45,51)
Given that L is the length of the wire, for how many values of L ≤ 1,500,000 can exactly one integer sided right angle triangle be formed?
Our solution is given in the TypeScript files below. This solution uses more than one code file. Some solutions use utilities which were created and enhanced while working on this and previous Project Euler problems. Some code in the utilities files might not be used in this particular problem.
This implementation found the solution in 173ms.
If you would like to view the answer, click below to reveal. Please consider reviewing the implementation and trying to code your own solution before viewing the answer.
The answer is 161667.
All of our solutions are hosted on GitHub. The code on this page was pulled from the repo and the solution and execution time were calculated based on that code.