Skip to content

Commit a81084c

Browse files
author
Christian Bender
authored
Refactoring solv1.py
Little embellishment of the code. I put some comments and put readable identifiers. I documented the code.
1 parent 31ebde6 commit a81084c

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

Diff for: Project Euler/Problem 04/sol1.py

+22-9
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,26 @@
33
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 x 99.
44
Find the largest palindrome made from the product of two 3-digit numbers which is less than N.
55
'''
6-
n=int(input())
7-
for i in range(n-1,10000,-1):
8-
temp=str(i)
9-
if(temp==temp[::-1]):
10-
j=999
11-
while(j!=99):
12-
if((i%j==0) and (len(str(i/j))==3)):
13-
print i
6+
limit = int(input("limit? "))
7+
8+
# fetchs the next number
9+
for number in range(limit-1,10000,-1):
10+
11+
# converts number into string.
12+
strNumber = str(number)
13+
14+
# checks whether 'strNumber' is a palindrome.
15+
if(strNumber == strNumber[::-1]):
16+
17+
divisor = 999
18+
19+
# if 'number' is a product of two 3-digit numbers
20+
# then number is the answer otherwise fetch next number.
21+
while(divisor != 99):
22+
23+
if((number % divisor == 0) and (len(str(number / divisor)) == 3)):
24+
25+
print number
1426
exit(0)
15-
j-=1
27+
28+
divisor -=1

0 commit comments

Comments
 (0)