x=0# assuming number is Xnnnnn 1st digit
y=0# assuming number is nYnnnn 2nd digit
z=0# assuming number is nnZnnn 3rd digit
num=999#highest 3 digit number
palidromefound=Falsehighestnum=num*numwhilestr(highestnum)!=str(highestnum)[::-1]:z=int(highestnum/1000)z=z%10y=int(highestnum/10000)y=y%10x=int(highestnum/100000)x=x%10ifz!=0andy!=0:z=z-1# first time find the highest palidrom
highestnum=(x*100000+y*10000+z*1000+z*100+y*10+x)whilepalidromefound==False:ifstr(highestnum)==str(highestnum)[::-1]:whilenum>99:if(highestnum%num)==0and(highestnum/num)<999and(highestnum/num)>99:palidromefound=Trueprint(f'Highest Palidrom: {highestnum} num1: {num} and num2: {int(highestnum / num)}')breaknum=num-1else:num=999# below are the palidromes.. the value of z is the 3rd digit, it comes from the above logic
# when the first highest palidrom is found, but if it not a multiple of two three digit numbers
# then the next highest palidrome is obtained:
#
# 992299 - 1100 = 991199 >> when z != 0
# 991199 - 1100 = 990099 >> when z != 0
# 990099 - 110 = 989989 >> when z == 0
# 989989 - 1100 = 988889 >> when z != 0
ifz==0:highestnum=highestnum-110z=9else:highestnum=highestnum-1100z=z-1
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Solution in Python: