File tree 3 files changed +14
-12
lines changed
3 files changed +14
-12
lines changed Original file line number Diff line number Diff line change 1
1
"""
2
- Problem Statement:
2
+ Problem 9: https://projecteuler.net/problem=9
3
+
3
4
A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
4
5
a^2 + b^2 = c^2
5
6
For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
9
10
"""
10
11
11
12
12
- def solution ():
13
+ def solution () -> int :
13
14
"""
14
15
Returns the product of a,b,c which are Pythagorean Triplet that satisfies
15
16
the following:
@@ -29,7 +30,7 @@ def solution():
29
30
return a * b * c
30
31
31
32
32
- def solution_fast ():
33
+ def solution_fast () -> int :
33
34
"""
34
35
Returns the product of a,b,c which are Pythagorean Triplet that satisfies
35
36
the following:
Original file line number Diff line number Diff line change 1
1
"""
2
- Problem Statement:
2
+ Problem 9: https://projecteuler.net/problem=9
3
+
3
4
A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
4
5
a^2 + b^2 = c^2
5
6
For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
9
10
"""
10
11
11
12
12
- def solution (n ) :
13
+ def solution (n : int = 1000 ) -> int :
13
14
"""
14
15
Return the product of a,b,c which are Pythagorean Triplet that satisfies
15
16
the following:
16
17
1. a < b < c
17
18
2. a**2 + b**2 = c**2
18
- 3. a + b + c = 1000
19
+ 3. a + b + c = n
19
20
20
21
>>> solution(1000)
21
22
31875000
22
23
"""
23
24
product = - 1
24
- d = 0
25
+ candidate = 0
25
26
for a in range (1 , n // 3 ):
26
27
"""Solving the two equations a**2+b**2=c**2 and a+b+c=N eliminating c"""
27
28
b = (n * n - 2 * a * n ) // (2 * n - 2 * a )
28
29
c = n - a - b
29
30
if c * c == (a * a + b * b ):
30
- d = a * b * c
31
- if d >= product :
32
- product = d
31
+ candidate = a * b * c
32
+ if candidate >= product :
33
+ product = candidate
33
34
return product
34
35
35
36
Original file line number Diff line number Diff line change 1
1
"""
2
- Problem Statement:
2
+ Problem 9: https://projecteuler.net/problem=9
3
3
4
4
A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
5
5
12
12
"""
13
13
14
14
15
- def solution ():
15
+ def solution () -> int :
16
16
"""
17
17
Returns the product of a,b,c which are Pythagorean Triplet that satisfies
18
18
the following:
You can’t perform that action at this time.
0 commit comments