From 42d42c3136e7f3592380bfe7b4c4d99f053fdc29 Mon Sep 17 00:00:00 2001 From: Sanders Lin <45224617+SandersLin@users.noreply.github.com> Date: Mon, 11 Feb 2019 10:42:43 +0800 Subject: [PATCH] Project Euler problem 4 sol 2 small fix (#632) --- project_euler/problem_04/sol2.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/project_euler/problem_04/sol2.py b/project_euler/problem_04/sol2.py index 68284ed34..70810c389 100644 --- a/project_euler/problem_04/sol2.py +++ b/project_euler/problem_04/sol2.py @@ -4,16 +4,14 @@ A palindromic number reads the same both ways. The largest palindrome made from Find the largest palindrome made from the product of two 3-digit numbers which is less than N. ''' from __future__ import print_function -arr = [] -for i in range(999,100,-1): - for j in range(999,100,-1): +n = int(input().strip()) +answer = 0 +for i in range(999,99,-1): #3 digit nimbers range from 999 down to 100 + for j in range(999,99,-1): t = str(i*j) - if t == t[::-1]: - arr.append(i*j) -arr.sort() + if t == t[::-1] and i*j < n: + answer = max(answer,i*j) +print(answer) +exit(0) + -n=int(input()) -for i in arr[::-1]: - if(i