mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-19 10:07:46 -05:00
1.8 KiB
1.8 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 6939b873185d8e00d453563e | Challenge 159: Integer Hypotenuse | 29 | challenge-159 |
--description--
Given two positive integers representing the lengths for the two legs (the two short sides) of a right triangle, determine whether the hypotenuse is an integer.
The length of the hypotenuse is calculated by adding the squares of the two leg lengths together and then taking the square root of that total (a2 + b2 = c2).
--hints--
is_integer_hypotenuse(3, 4) should return True.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_integer_hypotenuse(3, 4), True)`)
}})
is_integer_hypotenuse(2, 3) should return False.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_integer_hypotenuse(2, 3), False)`)
}})
is_integer_hypotenuse(5, 12) should return True.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_integer_hypotenuse(5, 12), True)`)
}})
is_integer_hypotenuse(10, 10) should return False.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_integer_hypotenuse(10, 10), False)`)
}})
is_integer_hypotenuse(780, 1040) should return True.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_integer_hypotenuse(780, 1040), True)`)
}})
is_integer_hypotenuse(250, 333) should return False.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_integer_hypotenuse(250, 333), False)`)
}})
--seed--
--seed-contents--
def is_integer_hypotenuse(a, b):
return a
--solutions--
import math
def is_integer_hypotenuse(a, b):
total = a*a + b*b
c = math.isqrt(total)
return c*c == total