← Back to challenges

Pythagorean Triplet

PythonHardmathvalidationnumbersgeometry

Instructions

Create a function that validates whether three given integers form a Pythagorean triplet. The sum of the squares of the two smallest integers must equal the square of the largest number to be validated.

Examples

is_triplet(3, 4, 5) ➞ True
# 3² + 4² = 25
# 5² = 25

is_triplet(13, 5, 12) ➞ True
# 5² + 12² = 169
# 13² = 169

is_triplet(1, 2, 3) ➞ False
# 1² + 2² = 5
# 3² = 9

Notes

Numbers may not be given in a sorted order.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Count Ones in Binary Representation of Integer