From a7b9e28bc34478850ea22e31f1d5a022502e2350 Mon Sep 17 00:00:00 2001 From: Maxim Smolskiy Date: Tue, 21 Sep 2021 14:28:27 +0300 Subject: [PATCH] Improve Project Euler problem 009 solution 1 (#4749) * Improve solution * Uncomment code that has been commented due to slow execution affecting Travis --- project_euler/problem_009/sol1.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/project_euler/problem_009/sol1.py b/project_euler/problem_009/sol1.py index a58ea943e..c50dfeecf 100644 --- a/project_euler/problem_009/sol1.py +++ b/project_euler/problem_009/sol1.py @@ -25,18 +25,16 @@ def solution() -> int: 2. a**2 + b**2 = c**2 3. a + b + c = 1000 - # The code below has been commented due to slow execution affecting Travis. - # >>> solution() - # 31875000 + >>> solution() + 31875000 """ for a in range(300): - for b in range(400): - for c in range(500): - if a < b < c: + for b in range(a + 1, 400): + for c in range(b + 1, 500): + if (a + b + c) == 1000: if (a ** 2) + (b ** 2) == (c ** 2): - if (a + b + c) == 1000: - return a * b * c + return a * b * c def solution_fast() -> int: @@ -47,9 +45,8 @@ def solution_fast() -> int: 2. a**2 + b**2 = c**2 3. a + b + c = 1000 - # The code below has been commented due to slow execution affecting Travis. - # >>> solution_fast() - # 31875000 + >>> solution_fast() + 31875000 """ for a in range(300):