Skip to content

Commit 028055e

Browse files
committed
Add documentation and tests for the Euler project problem 136 solution.
1 parent cde6389 commit 028055e

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Diff for: project_euler/problem_136/sol1.py

+34
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,41 @@
1+
"""
2+
Project Euler Problem 136: https://projecteuler.net/problem=136
3+
4+
Singleton Difference
5+
6+
By change of variables
7+
8+
x = y + delta
9+
z = y - delta
10+
11+
The expression can be rewritten:
12+
13+
x^2 - y^2 - z^2 = y*(4*delta - y) = n
14+
15+
The algorithm loops over delta and y, which is restricted in upper and lower limits,
16+
to count how many solutions each n has.
17+
In the end it is counted how many n's have one solution.
18+
19+
20+
>>> solution(100)
21+
25
22+
"""
23+
124
N = 50000000
225

326

427
def solution(n_limit: int = N) -> int:
28+
"""
29+
Define n count list and loop over delta, y to get the counts, then check
30+
which n has count == 1.
31+
32+
>>> solution(3)
33+
0
34+
>>> solution(10)
35+
2
36+
>>> solution(110)
37+
26
38+
"""
539
n_sol = [0] * n_limit
640

741
for delta in range(1, (n_limit + 1) // 4):

0 commit comments

Comments
 (0)