Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 42d42c3

Browse files
SandersLinpoyea
authored andcommitted
Project Euler problem 4 sol 2 small fix (TheAlgorithms#632)
1 parent dbe3f06 commit 42d42c3

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

‎project_euler/problem_04/sol2.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@
44
Find the largest palindrome made from the product of two 3-digit numbers which is less than N.
55
'''
66
from __future__ import print_function
7-
arr = []
8-
for i in range(999,100,-1):
9-
for j in range(999,100,-1):
7+
n = int(input().strip())
8+
answer = 0
9+
for i in range(999,99,-1): #3 digit nimbers range from 999 down to 100
10+
for j in range(999,99,-1):
1011
t = str(i*j)
11-
if t == t[::-1]:
12-
arr.append(i*j)
13-
arr.sort()
12+
if t == t[::-1] and i*j < n:
13+
answer = max(answer,i*j)
14+
print(answer)
15+
exit(0)
16+
1417

15-
n=int(input())
16-
for i in arr[::-1]:
17-
if(i<n):
18-
print(i)
19-
exit(0)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /