File tree 1 file changed +22
-9
lines changed
1 file changed +22
-9
lines changed Original file line number Diff line number Diff line change 3
3
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.
4
4
Find the largest palindrome made from the product of two 3-digit numbers which is less than N.
5
5
'''
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
14
26
exit (0 )
15
- j -= 1
27
+
28
+ divisor -= 1
You can’t perform that action at this time.
0 commit comments