%I #16 Jun 24 2022 14:07:03
%S 0,1,2,3,4,5,6,7,8,9,0,11,11,11,11,11,11,11,11,11,0,11,22,22,22,22,22,
%T 22,22,22,0,11,22,33,33,33,33,33,33,33,0,11,22,33,44,44,44,44,44,44,0,
%U 11,22,33,44,55,55,55,55,55,0,11,22,33,44,55,66,66,66,66,0,11,22,33,44,55,66,77,77,77,0,11,22,33
%N a(n) = largest base-10 palindrome m <= n such that every base-10 digit of m is <= the corresponding digit of n.
%H Reinhard Zumkeller, <a href="/A265525/b265525.txt">Table of n, a(n) for n = 0..9999</a>
%p ispal := proc(n) # test for base-b palindrome
%p local L, Ln, i;
%p global b;
%p L := convert(n, base, b);
%p Ln := nops(L);
%p for i to floor(1/2*Ln) do
%p if L[i] <> L[Ln + 1 - i] then return false end if
%p end do;
%p return true
%p end proc
%p # find max pal <= n and in base-b shadow of n, write in base 10
%p under10:=proc(n) global b;
%p local t1,t2,i,m,sw1,L2;
%p if n mod b = 0 then return(0); fi;
%p t1:=convert(n,base,b);
%p for m from n by -1 to 0 do
%p if ispal(m) then
%p t2:=convert(m,base,b);
%p L2:=nops(t2);
%p sw1:=1;
%p for i from 1 to L2 do
%p if t2[i] > t1[i] then sw1:=-1; break; fi;
%p od:
%p if sw1=1 then return(m); fi;
%p fi;
%p od;
%p end proc;
%p b:=10; [seq(under10(n),n=0..144)]; # Gives A265525
%o (Haskell)
%o a265525 n = a265525_list !! n
%o a265525_list = f a031298_tabf [[]] where
%o f (ds:dss) pss = y : f dss pss' where
%o y = foldr (\d v -> 10 * v + d) 0 ys
%o (ys:_) = dropWhile (\ps -> not $ and $ zipWith (<=) ps ds) pss'
%o pss' = if ds /= reverse ds then pss else ds : pss
%o -- _Reinhard Zumkeller_, Dec 11 2015
%Y Sequences related to palindromic floor and ceiling: A175298, A206913, A206914, A261423, A262038, and the large block of consecutive sequences beginning at A265509.
%Y Cf. A002113, A031298, A265558.
%K nonn,base,look
%O 0,3
%A _N. J. A. Sloane_, Dec 09 2015
|