project_euler.problem_142.sol1¶
Project Euler Problem 142: https://projecteuler.net/problem=142
Perfect Square Collection
Find the smallest x + y + z with integers x > y > z > 0 such that x + y, x - y, x + z, x - z, y + z, y - z are all perfect squares.
Change the variables to a, b, c, so that 3 requirements are satisfied automatically: a^2 = y - z b^2 = x - y c^2 = z + x
and the rest of requirements for perfect squares are: z + y = c^2 - b^2 y + x = a^2 + c^2 x - z = a^2 + b^2
Then iterate over a^2, b^2 and c^2 to check if the combination satisfies all 3 requirements.
The total sum x + y + z = (a^2 - b^2 + 3c^2) / 2, so we break loop for c^2 if the sum is already bigger than found sum.
Functions¶
|
Iterate over combinations of a, b, c and save min sum. |
Module Contents¶
- project_euler.problem_142.sol1.solution(number_of_terms: int = 3) int | None¶
Iterate over combinations of a, b, c and save min sum. In case only one term x = 1 is solution. In case of two terms, x = 5, y = 4 is the solution.
>>> solution(1) 1 >>> solution(2) 9