cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A261423 Largest palindrome <= n.

Original entry on oeis.org

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 77, 77
Offset: 0

Views

Author

N. J. A. Sloane, Aug 28 2015

Keywords

Comments

Might be called the palindromic floor function.
Let P(n) = n with the second half of its digits replaced by the first half of the digits in reverse order. If P(n) <= n, then a(n) = P(n), else if n=10^k then a(n) = n-1, else a(n) = P(n-10^floor(d/2)), where d is the number of digits of n. - M. F. Hasler, Sep 08 2015
The largest differences of n - a(n) occur for n = m*R(2k) - 1, where 1 <= m <= 9 and R(k)=(10^k-1)/9. In this case, n - a(n) = 1.1*10^k - 1. - M. F. Hasler, Sep 05 2018

Crossrefs

Cf. A002113, A261424, A261914 (previous palindrome).
Cf. A262038.
Sequences related to palindromic floor and ceiling: A175298, A206913, A206914, A261423, A262038, and the large block of consecutive sequences beginning at A265509.
A262257(n) = Levenshtein distance between n and a(n). - Reinhard Zumkeller, Sep 16 2015

Programs

  • Haskell
    a261423 n = a261423_list !! n
    a261423_list = tail a261914_list  -- Reinhard Zumkeller, Sep 16 2015
    
  • Maple
    # P has list of palindromes
    palfloor:=proc(n) global P; local i;
    for i from 1 to nops(P) do
       if P[i]=n then return(n); fi;
       if P[i]>n then return(P[i-1]); fi;
    od:
    end;
  • Mathematica
    palQ[n_] := Block[{d = IntegerDigits@ n}, d == Reverse@ d]; Table[k = n;
    While[Nand[palQ@ k, k > -1], k--]; k, {n, 0, 78}] (* Michael De Vlieger, Sep 09 2015 *)
  • PARI
    A261423(n,d=digits(n),m=sum(k=1,#d\2,d[k]*10^(k-1)))={if( n%10^(#d\2)M. F. Hasler, Sep 08 2015, minor edit on Sep 05 2018
    
  • Python
    def P(n):
        s = str(n); h = s[:(len(s)+1)//2]; return int(h + h[-1-len(s)%2::-1])
    def a(n):
        s = str(n)
        if s == '1'+'0'*(len(s)-1) and n > 1: return n - 1
        Pn = P(n)
        return Pn if Pn <= n else P(n - 10**(len(s)//2))
    print([a(n) for n in range(79)]) # Michael S. Branicky, Jun 25 2021

Formula

n - a(n) < 1.1*10^floor(d/2), where d = floor(log_10(n)) + 1 is the number of digits of n. - M. F. Hasler, Sep 05 2018