OFFSET
1,2
COMMENTS
This sequence is a permutation of the nonnegative integers.
See A245234 for the inverse permutation.
From M. F. Hasler, Apr 22 2024: (Start)
Due to the offset 1, this isn't a permutation of the nonnegative integers stricto sensu (but a bijection from positive integers to nonnegative integers), and the only fixed point appears to be a(18) = 18.
If the offset was chosen to be zero, the list of fixed points of this sequence would be 0, 19, 20, 85, 885, 1007, 1017, 1027, 4603, 5353, ...
By construction/definition, the terms a(2k-1) are always smaller than all subsequent terms a(m), m > 2k-1, k > 0. Therefore, when the "reversal" A004086(a(2k-1)) > a(2k-1), then a(2k) = A004086(a(2k-1)): this obviously yields a palindromic pair (a(2k-1), a(2k)), and any smaller a(2k) with this property would have to be a left-truncation of this term, which would have less digits and therefore be strictly smaller and have occurred earlier than a(2k-1).
Otherwise, when A004086(a(2k-1)) <= a(2k-1), in particular when a(2k-1) is a palindrome or divisible by 10 or when A000030(a(2k-1)) > A010879(a(2k-1)) (first digit > last digit), then a(m) = A004086(a(2k-1)) for some m < 2k-1, and in this case, a(2k) = A004086(a(2k-1)*10+1) (except for a(2) = 10 where 10*a(1) vanishes) is the smallest possible number that yields a palindromic pair: again, any smaller solution would have to be a left truncation of this, which all have occurred earlier. (End)
LINKS
Giovanni Resta, Table of n, a(n) for n = 1..10000
FORMULA
From M. F. Hasler, Apr 22 2024: (Start)
a(2k) = A004086(a(2k-1)) if this is greater than a(2k-1), else A004086(a(2k-1)*10+1), for all k > 0.
A000030(a(2k-1)) = A010879(a(2k)) for all k > 0, where A000030 = initial digit and A010879(m) = m % 10 = final digit of m.
A010879(a(2k)) > 0 for all k > 1: a(2) is the only even-indexed term multiple of 10. (End)
EXAMPLE
(0,10), (1,11), (2,12), (3,13), (4,14), (5,15), ...: The palindromic pattern is clearly visible in each pair.
MATHEMATICA
(* first 10000 terms *) s = {0, 10}; t = 0*Range[20000]; t[[10]] = 1; Do[ j = Position[t, 0, 1, 1][[1, 1]]; AppendTo[s, j]; t[[j]] = 1; d = IntegerDigits[j]; h = 1; While[t[[h]] == 1 || (p = Join[d, IntegerDigits[h]]; p != Reverse[p]), h++]; AppendTo[s, h]; t[[h]] = 1; If[Mod[Length@s, 500] == 0, Print[Length@s, " ", {j, h}]], {4999}]; s (* Giovanni Resta, Mar 06 2014 *)
PROG
(Haskell)
import Data.List (delete)
a238880 n = a238880_list !! (n-1)
a238880_list = f [0..] where
f (u:us) = u : g us where
g vs = h vs where
h (w:ws) = if reverse ys == ys then w : f (delete w vs) else h ws
where ys = xs ++ show w
xs = show u
-- Reinhard Zumkeller, Jul 14 2014
(PARI)
A238880_upto(N, U=[-1])={vector(N, n, U=setunion(U, [N=if(n%2, U[1]+1, N < n=fromdigits(Vecrev(digits(N))), n, n+10^logint(N+!N, 10)*10)]); while(#U>1&& U[1]+1==U[2], U=U[^1]); N)} \\ M. F. Hasler, Apr 22 2024
(Python)
def A238880(n: int) -> int:
try: return A238880.terms[n-1]
except IndexError: T = A238880.terms # more terms needed
while len(T) < n:
if len(T) & 1 == 0: x = A238880.least_unused # even index
elif T[-1] >= (x := int(s := str(T[-1])[::-1])): x = int('1'+s)
T.append(x)
if x == A238880.least_unused: # also e.g. for a(20) = 19
while x+1 in T: x += 1
A238880.least_unused = x+1
return T[n-1] # M. F. Hasler, Apr 19 2024, simplified Apr 22, 2024
CROSSREFS
KEYWORD
AUTHOR
Eric Angelini, Mar 06 2014
STATUS
approved