Answer the question
In order to leave comments, you need to log in
How can you improve the algorithm for finding the largest palindrome number in the product of two numbers?
Good evening.
I'm trying to solve a problem.
Wrote a script:
def isPolindrom(mystr):
str_reverse = mystr[::-1]
if str_reverse == mystr:
# print(mystr)
return True
return False
def euler4():
numbers = [ {
"num": 99999,
"i": 0
} ]
polindromHasFound = False
polindroms = []
while not polindromHasFound:
nextNum = numbers[len(numbers) - 1]['num'] - 1
for el in numbers:
numForTest = el["num"] * (el["num"] - el["i"])
if isPolindrom( str(numForTest) ):
polindroms.insert( len(polindroms), numForTest )
el["i"] += 1
if len(polindroms) >= 100:
print( polindroms )
print( max(polindroms) )
polindromHasFound = True
if numbers[0]["i"] != 0:
numbers.insert( len(numbers), {
"num": nextNum,
"i": 0
} )
euler4();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question