File tree 1 file changed +34
-0
lines changed
project_euler/problem_136
1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
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
+
1
24
N = 50000000
2
25
3
26
4
27
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
+ """
5
39
n_sol = [0 ] * n_limit
6
40
7
41
for delta in range (1 , (n_limit + 1 ) // 4 ):
You can’t perform that action at this time.
0 commit comments