project_euler.problem_009.sol4¶
Project Euler Problem 9: https://projecteuler.net/problem=9
Special Pythagorean triplet
A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
a^2 + b^2 = c^2.
For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc.
- References:
Functions¶
|
|
|
Precomputing squares and checking if a^2 + b^2 is the square by set look-up. |
Module Contents¶
- project_euler.problem_009.sol4.get_squares(n: int) list[int] ¶
>>> get_squares(0) [] >>> get_squares(1) [0] >>> get_squares(2) [0, 1] >>> get_squares(3) [0, 1, 4] >>> get_squares(4) [0, 1, 4, 9]
- project_euler.problem_009.sol4.solution(n: int = 1000) int ¶
Precomputing squares and checking if a^2 + b^2 is the square by set look-up.
>>> solution(12) 60 >>> solution(36) 1620