© 2024 fjorge. All rights reserved.
Project Euler Problem 9

I've been having some fun doing the first few problems of Project Euler and figured I'd share my solution to problem 9 here.
The Problem
A Pythagorean triplet is a set of three natural numbers, a b c, for which, a^2 + b^2 = c^2
There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc.
The Solution
This is pretty basic and inefficient, but I decided to loop through a and b, calculating c from the difference.
There you have it, the program stops at a^2 + b^2 = c^2 where c = (1000 – a – b). I then took a*b*c to get the answer.