Skip to content

Commit abf39d8

Browse files
archaengelstokhos
authored andcommitted
Add style improvements to Project Euler problem 9 (TheAlgorithms#3046)
1 parent dbf54a1 commit abf39d8

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

Diff for: project_euler/problem_09/sol1.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""
2-
Problem Statement:
2+
Problem 9: https://projecteuler.net/problem=9
3+
34
A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
45
a^2 + b^2 = c^2
56
For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
@@ -9,7 +10,7 @@
910
"""
1011

1112

12-
def solution():
13+
def solution() -> int:
1314
"""
1415
Returns the product of a,b,c which are Pythagorean Triplet that satisfies
1516
the following:
@@ -29,7 +30,7 @@ def solution():
2930
return a * b * c
3031

3132

32-
def solution_fast():
33+
def solution_fast() -> int:
3334
"""
3435
Returns the product of a,b,c which are Pythagorean Triplet that satisfies
3536
the following:

Diff for: project_euler/problem_09/sol2.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""
2-
Problem Statement:
2+
Problem 9: https://projecteuler.net/problem=9
3+
34
A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
45
a^2 + b^2 = c^2
56
For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
@@ -9,27 +10,27 @@
910
"""
1011

1112

12-
def solution(n):
13+
def solution(n: int = 1000) -> int:
1314
"""
1415
Return the product of a,b,c which are Pythagorean Triplet that satisfies
1516
the following:
1617
1. a < b < c
1718
2. a**2 + b**2 = c**2
18-
3. a + b + c = 1000
19+
3. a + b + c = n
1920
2021
>>> solution(1000)
2122
31875000
2223
"""
2324
product = -1
24-
d = 0
25+
candidate = 0
2526
for a in range(1, n // 3):
2627
"""Solving the two equations a**2+b**2=c**2 and a+b+c=N eliminating c"""
2728
b = (n * n - 2 * a * n) // (2 * n - 2 * a)
2829
c = n - a - b
2930
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
3334
return product
3435

3536

Diff for: project_euler/problem_09/sol3.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Problem Statement:
2+
Problem 9: https://projecteuler.net/problem=9
33
44
A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
55
@@ -12,7 +12,7 @@
1212
"""
1313

1414

15-
def solution():
15+
def solution() -> int:
1616
"""
1717
Returns the product of a,b,c which are Pythagorean Triplet that satisfies
1818
the following:

0 commit comments

Comments
 (0)