What is the smallest positive integer N such that N+123456 and N+12345678 are both palindromic?
For example, the smallest whole number such that N+1234 and N+123456 are both palindromic is N=975445, since:975445+1234=976679 and 975445+123456=1098901.
Notice the alternating patterns
N N+1 N+123
8 9 131
N N+12 N+1234
9877 9889 11111
N N+123 N+12345
786 909 13131
N N+1234 N+123456
975445 976679 1098901
N N+12345 N+1234567
78564 90909 1313131
N N+123456 N+12345678
97543223 97666679 109888901
N N+1234567 N+123456789
7856342 9090909 131313131
----------
for k in range(1,8):
print('starting', k)
sa = ''
sb = ''
for i in range(1, k+3):
sb += str(i)
if i>k:
continue
sa += str(i)
a = int(sa)
b = int(sb)
for n in range(1,10000000000):
x = n+a
sx = str(x)
if sx != sx[::-1]:
continue
y = n+b
sy = str(y)
if sy != sy[::-1]:
continue
print(a, n, int(x), int(y))
break
Edited on April 10, 2024, 12:43 pm
|
Posted by Larry
on 2024-04-10 12:39:42 |