Skip to content

Commit 6305d59

Browse files
Update sol4.py
1 parent eea44fc commit 6305d59

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

project_euler/problem_009/sol4.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def get_squares(n: int) -> list[int]:
3535

3636
def solution(n: int = 1000) -> int:
3737
"""
38-
Precomputing squares and checking if a*a + b*b is the square by set look-up.
38+
Precomputing squares and checking if a^2 + b^2 is the square by set look-up.
3939
4040
>>> solution(12)
4141
60
@@ -45,13 +45,13 @@ def solution(n: int = 1000) -> int:
4545

4646
squares = get_squares(n)
4747
squares_set = set(squares)
48-
for i in range(1, n):
49-
for j in range(i, n):
48+
for a in range(1, n // 3):
49+
for b in range(a + 1, (n - a) // 2):
5050
if (
51-
squares[i] + squares[j] in squares_set
52-
and squares[n - i - j] == squares[i] + squares[j]
51+
squares[a] + squares[b] in squares_set
52+
and squares[n - a - b] == squares[a] + squares[b]
5353
):
54-
return i * j * (n - i - j)
54+
return a * b * (n - a - b)
5555

5656
return -1
5757

0 commit comments

Comments
 (0)