← all problems

pythagoreanTriples 🌶️🌶️🌶️

A Pythagorean triple is three positive whole numbers a < b < c with a a + b b == c * c, like 3, 4, 5. Write a method pythagoreanTriples that takes an int limit and returns how many triples have c less than or equal to limit. Use nested loops.

For example, pythagoreanTriples(5) is 1 (just 3, 4, 5), and pythagoreanTriples(20) is 6.