We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent dbe3f06 commit 42d42c3Copy full SHA for 42d42c3
project_euler/problem_04/sol2.py
@@ -4,16 +4,14 @@
4
Find the largest palindrome made from the product of two 3-digit numbers which is less than N.
5
'''
6
from __future__ import print_function
7
-arr = []
8
-for i in range(999,100,-1):
9
- 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
10
+ for j in range(999,99,-1):
11
t = str(i*j)
- if t == t[::-1]:
12
- arr.append(i*j)
13
-arr.sort()
+ if t == t[::-1] and i*j < n:
+ answer = max(answer,i*j)
14
+print(answer)
15
+exit(0)
16
+
17
-n=int(input())
-for i in arr[::-1]:
- if(i<n):
18
- print(i)
19
- exit(0)
0 commit comments