From a5000d32edf1992615ecdb112e112b0490e5ddd3 Mon Sep 17 00:00:00 2001 From: Edward Nuno Date: Tue, 6 Oct 2020 22:03:34 -0700 Subject: [PATCH] Add style improvements to solutions for Project Euler Problem 04 (#2945) * Fix typehints in project_euler/problem01 Squashed commit of the following: commit 6801d073b31bf702814861cd3b07b634ca295bfa Author: Archaengel Date: Mon Oct 5 16:40:10 2020 -0700 Fix typehints in project_euler/problem01 commit 29afc3af114abd1b99dc3f7c8fc99128229db131 Author: Archaengel Date: Mon Oct 5 15:06:34 2020 -0700 Add typehints and default argument for project_euler/problem_01 * Add default args, typehints, and expand variable names for PE prob 02 * Add style improvements for first solution of PE Problem 02 * Add default arg and typehints for second solution of PE Problem 02 * Add default arg for third solution of PE Problem 02 * Add style improvements for 1st soln of PE problem 03 * Add default arg and typehints for 2nd soln of PE problem 03 * Add default arg for 3rd soln of PE problem 03 * Remove unnecessary newlines * Remove unnecessary newlines * Fix end of file for 2nd soln in PE problem 03 * Add style improvements to solutions for PE problem 04 * Restore original newlines in soln for PE problem 04 * Fix punctuation in docstring for PE problem 04 * Restore solution bodies for PE problem 04 * Expand variable names for 2nd soln of PE problem 04 --- project_euler/problem_04/sol1.py | 2 +- project_euler/problem_04/sol2.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/project_euler/problem_04/sol1.py b/project_euler/problem_04/sol1.py index 227b594d0..42f56f3ef 100644 --- a/project_euler/problem_04/sol1.py +++ b/project_euler/problem_04/sol1.py @@ -8,7 +8,7 @@ is less than N. """ -def solution(n): +def solution(n: int = 998001) -> int: """Returns the largest palindrome made from the product of two 3-digit numbers which is less than n. diff --git a/project_euler/problem_04/sol2.py b/project_euler/problem_04/sol2.py index 0f185f121..8ee082ad2 100644 --- a/project_euler/problem_04/sol2.py +++ b/project_euler/problem_04/sol2.py @@ -8,7 +8,7 @@ is less than N. """ -def solution(n): +def solution(n: int = 998001) -> int: """Returns the largest palindrome made from the product of two 3-digit numbers which is less than n. @@ -22,8 +22,8 @@ def solution(n): answer = 0 for i in range(999, 99, -1): # 3 digit numbers range from 999 down to 100 for j in range(999, 99, -1): - t = str(i * j) - if t == t[::-1] and i * j < n: + product_string = str(i * j) + if product_string == product_string[::-1] and i * j < n: answer = max(answer, i * j) return answer