top of page

Finding the Pythagorean Triplet: Project Euler Problem 9
6 days ago
1 min read
0
2
0

The Challenge
Project Euler Problem 9 asks us to find the unique Pythagorean triplet where a + b + c = 1000, then calculate the product abc.
A Pythagorean triplet consists of three natural numbers a, b, c where:
a² + b² = c²
The classic example being 3² + 4² = 5² (9 + 16 = 25)
The Brute Force Approach
The solution above takes a straightforward nested loop approach:
python
import math
for a in range(0,1000):
for b in range(0,1000):
for c in range(0,1000):
if a < b < c:
if (a * a) + (b * b) == (c * c):
if a + b + c == 1000:
print(a * b * c)This works by:
Testing all possible combinations of a, b, and c from 0 to 999
Ensuring proper ordering (a < b < c)
Checking the Pythagorean theorem condition
Verifying the sum equals 1000
The Result
Running this code finds: a = 200, b = 375, c = 425
The product: 200 × 375 × 425 = 31,875,000
Related Posts
Comments
Share Your ThoughtsBe the first to write a comment.
bottom of page





