Skip to content

Commit 58485a1

Browse files
Update sol1.py
1 parent 028055e commit 58485a1

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

Diff for: project_euler/problem_136/sol1.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,29 @@
33
44
Singleton Difference
55
6+
The positive integers, x, y, and z, are consecutive terms of an arithmetic progression.
7+
Given that n is a positive integer, the equation, x^2 - y^2 - z^2 = n, has exactly one solution when n = 20:
8+
13^2 - 10^2 - 7^2 = 20.
9+
10+
In fact there are twenty-five values of n below one hundred for which the equation has a unique solution.
11+
12+
How many values of n less than fifty million have exactly one solution?
13+
614
By change of variables
715
816
x = y + delta
917
z = y - delta
1018
1119
The expression can be rewritten:
1220
13-
x^2 - y^2 - z^2 = y*(4*delta - y) = n
21+
x^2 - y^2 - z^2 = y * (4 * delta - y) = n
1422
1523
The algorithm loops over delta and y, which is restricted in upper and lower limits,
1624
to count how many solutions each n has.
1725
In the end it is counted how many n's have one solution.
18-
19-
20-
>>> solution(100)
21-
25
2226
"""
2327

24-
N = 50000000
25-
26-
27-
def solution(n_limit: int = N) -> int:
28+
def solution(n_limit: int = 50 * 10**6) -> int:
2829
"""
2930
Define n count list and loop over delta, y to get the counts, then check
3031
which n has count == 1.
@@ -33,6 +34,8 @@ def solution(n_limit: int = N) -> int:
3334
0
3435
>>> solution(10)
3536
2
37+
>>> solution(100)
38+
25
3639
>>> solution(110)
3740
26
3841
"""

0 commit comments

Comments
 (0)