Aug-06-2020, 03:33 PM
Hi everyone!
I'm trying to familiarise myself with maths and CS, so I started doing these little Project Euler challenges.
This is the one I tried to code something to:
"A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
Find the largest palindrome made from the product of two 3-digit numbers."
I get this error message when I try to run it:
"if str(a*b)[n]==str(a*b)[m]:
IndexError: string index out of range"
I realize that either n or m or both become bigger than they should when the program runs, but I'm not sure when/why that happens, since I reset both n and m if the inspected digits turn out not to be the same.
I've been stuck on this problem for days. I would greatly appreciate your help!
I'm trying to familiarise myself with maths and CS, so I started doing these little Project Euler challenges.
This is the one I tried to code something to:
"A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
Find the largest palindrome made from the product of two 3-digit numbers."
I get this error message when I try to run it:
"if str(a*b)[n]==str(a*b)[m]:
IndexError: string index out of range"
I realize that either n or m or both become bigger than they should when the program runs, but I'm not sure when/why that happens, since I reset both n and m if the inspected digits turn out not to be the same.
I've been stuck on this problem for days. I would greatly appreciate your help!
a=999
b=999
n=0
m=(len(str(a*b))-1)
while n!=len(str(a*b))-1:
if str(a*b)[n]==str(a*b)[m]:
n=n+1
m=m-1
else:
n=0
m=(len(str(a*b))-1)
if len(str(b))==3:
b=b-1
else:
a=a-1
b=999
print(a*b)
print(b)
