Skip to content

Commit a7b9e28

Browse files
Improve Project Euler problem 009 solution 1 (TheAlgorithms#4749)
* Improve solution * Uncomment code that has been commented due to slow execution affecting Travis
1 parent 4761fef commit a7b9e28

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

project_euler/problem_009/sol1.py

+8-11
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,16 @@ def solution() -> int:
2525
2. a**2 + b**2 = c**2
2626
3. a + b + c = 1000
2727
28-
# The code below has been commented due to slow execution affecting Travis.
29-
# >>> solution()
30-
# 31875000
28+
>>> solution()
29+
31875000
3130
"""
3231

3332
for a in range(300):
34-
for b in range(400):
35-
for c in range(500):
36-
if a < b < c:
33+
for b in range(a + 1, 400):
34+
for c in range(b + 1, 500):
35+
if (a + b + c) == 1000:
3736
if (a ** 2) + (b ** 2) == (c ** 2):
38-
if (a + b + c) == 1000:
39-
return a * b * c
37+
return a * b * c
4038

4139

4240
def solution_fast() -> int:
@@ -47,9 +45,8 @@ def solution_fast() -> int:
4745
2. a**2 + b**2 = c**2
4846
3. a + b + c = 1000
4947
50-
# The code below has been commented due to slow execution affecting Travis.
51-
# >>> solution_fast()
52-
# 31875000
48+
>>> solution_fast()
49+
31875000
5350
"""
5451

5552
for a in range(300):

0 commit comments

Comments
 (0)