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.

Showing 1-10 of 69 results. Next

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

A262038 Least palindrome >= n.

Original entry on oeis.org

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 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, 77, 77, 77, 77, 77, 77, 77, 77
Offset: 0

Views

Author

M. F. Hasler, Sep 08 2015

Keywords

Comments

Could be called nextpalindrome() in analogy to the nextprime() function A007918. As for the latter (A151800), there is the variant "next strictly larger palindrome" which equals a(n+1), and thus differs from a(n) iff n is a palindrome; see PARI code.
Might also be called palindromic ceiling function in analogy to the name "palindromic floor" proposed for A261423.

Crossrefs

Sequences related to palindromic floor and ceiling: A175298, A206913, A206914, A261423, A262038, and the large block of consecutive sequences beginning at A265509.

Programs

  • Haskell
    a262038 n = a262038_list !! n
    a262038_list = f 0 a002113_list where
       f n ps'@(p:ps) = p : f (n + 1) (if p > n then ps' else ps)
    -- Reinhard Zumkeller, Sep 16 2015
    
  • Mathematica
    palQ[n_] := Block[{d = IntegerDigits@ n}, d == Reverse@ d]; Table[k = n; While[! palQ@ k, k++]; k, {n, 0, 80}] (* Michael De Vlieger, Sep 09 2015 *)
  • PARI
    {A262038(n, d=digits(n), p(d)=sum(i=1, #d\2, (10^(i-1)+10^(#d-i))*d[i],if(bittest(#d,0),10^(#d\2)*d[#d\2+1])))= for(i=(#d+3)\2,#d,d[i]>d[#d+1-i]&&break;(d[i]9||return(p(d));d[i]=0);10^#d+1} \\ For a function "next strictly larger palindrome", delete the i==#d and n<10... part. - M. F. Hasler, Sep 09 2015
    
  • Python
    def A262038(n):
        sl = len(str(n))
        l = sl>>1
        if sl&1:
            w = 10**l
            n2 = w*10
            for y in range(n//(10**l),n2):
                k, m = y//10, 0
                while k >= 10:
                    k, r = divmod(k,10)
                    m = 10*m + r
                z = y*w + 10*m + k
                if z >= n:
                    return z
        else:
            w = 10**(l-1)
            n2 = w*10
            for y in range(n//(10**l),n2):
                k, m = y, 0
                while k >= 10:
                    k, r = divmod(k,10)
                    m = 10*m + r
                z = y*n2 + 10*m + k
                if z >= n:
                    return z # Chai Wah Wu, Sep 14 2022

A206913 Greatest binary palindrome <= n; the binary palindrome floor function.

Original entry on oeis.org

0, 1, 1, 3, 3, 5, 5, 7, 7, 9, 9, 9, 9, 9, 9, 15, 15, 17, 17, 17, 17, 21, 21, 21, 21, 21, 21, 27, 27, 27, 27, 31, 31, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 45, 45, 45, 45, 45, 45, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 63, 63, 65, 65, 65, 65
Offset: 0

Views

Author

Hieronymus Fischer, Feb 13 2012

Keywords

Comments

Also the greatest binary palindrome < n + 1;
For n > 0, a(n-1) is the greatest binary palindrome < n.

Examples

			a(0) = 0 since 0 is the greatest binary palindrome <= 0;
a(1) = 1 since 1 is the greatest binary palindrome <= 1;
a(2) = 1 since 1 is the greatest binary palindrome <= 2;
a(3) = 3 since 3 is the greatest binary palindrome <= 3.
		

Crossrefs

Sequences related to palindromic floor and ceiling: A175298, A206913, A206914, A261423, A262038, and the large block of consecutive sequences beginning at A265509.

Programs

  • Haskell
    a206913 n = last $ takeWhile (<= n) a006995_list
    -- Reinhard Zumkeller, Feb 27 2012

Formula

Let n > 2, p = 1 + 2*floor((n-1)/2), m = floor(log_2(p)), q = floor((m+1)/2), s = floor(log_2(p-2^q)),
F(x, r) = floor(x/2^q)*2^q + Sum_{k = 0...q - 1} (floor(x/2^(r-k)) mod 2)*2^k;
If F(p, m) <= n then a(n) = F(p, m), otherwise a(n) = F(p-2^q, s).
By definition: F(p, m) = floor(p/2^q)*2^q + A030101(p) mod 2^q; also: F(p-2^q, s) = floor((p-2^q)/2^q)*2^q + A030101(p-2^q) mod 2^q; [Edited and corrected by Hieronymus Fischer, Sep 08 2018]
a(n) = A006995(A206915(n));
a(n) = A006995(A206915(A206914(n+1))-1);
a(n) = A006995(A206916(A206914(n+1))-1).

A175298 Smallest number >=n whose binary representation is palindromic and has a 1 whenever the binary representation of n has a 1.

Original entry on oeis.org

0, 1, 3, 3, 5, 5, 7, 7, 9, 9, 15, 15, 15, 15, 15, 15, 17, 17, 27, 27, 21, 21, 31, 31, 27, 27, 27, 27, 31, 31, 31, 31, 33, 33, 51, 51, 45, 45, 63, 63, 45, 45, 63, 63, 45, 45, 63, 63, 51, 51, 51, 51, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 65, 65, 99, 99, 85, 85, 119, 119, 73
Offset: 0

Views

Author

Leroy Quet, Mar 24 2010

Keywords

Comments

Old name: "Convert n to binary. OR each respective digit of binary n and binary A030101(n), where A030101(n) is the reversal of the order of the digits in the binary representation of n (given in decimal). a(n) is the decimal value of the result."
By "respective" digits of binary n and binary A030101(n), the rightmost digit of A030101(n) ( which is a 1) is OR'ed with the rightmost digit of n. A030101(n) is represented with the appropriate number of leading 0's.
This is the binary next-palindrome function, the base-2 analog of A262038. - N. J. A. Sloane, Dec 08 2015

Examples

			20 in binary is 10100. The reversal of the binary digits is 00101. So, from leftmost to rightmost respective digits, we OR 10100 and 00101: 1 OR 0 = 1. 0 OR 0 = 0. 1 OR 1 = 1. 0 OR 0 = 0. And 0 OR 1 = 1. So, 10100 OR 00101 is 10101, which is 21 in decimal. So a(20) = 21.
		

Crossrefs

Sequences related to palindromic floor and ceiling: A175298, A206913, A206914, A261423, A262038, and the large block of consecutive sequences beginning at A265509.

Programs

  • Mathematica
    Table[f = IntegerDigits[x, 2]; f = f + Reverse[f]; FromDigits[ Table[If[Positive[f[[r]]], 1, 0], {r, 1, Length[f]}], 2], {x, STARTPOINT, ENDPOINT}] (* Dylan Hamilton, Oct 15 2010 *)
    f[n_] := Block[{id = IntegerDigits[n, 2]}, FromDigits[ BitOr[ id, Reverse@id], 2]]; Array[f, 72] (* Robert G. Wilson v, Nov 07 2010 *)

Extensions

Extended, with redundant initial entries included, by Dylan Hamilton, Oct 15 2010
Edited with new name and offset by N. J. A. Sloane, Dec 08 2015

A206914 Least binary palindrome >= n; the binary palindrome ceiling function.

Original entry on oeis.org

0, 1, 3, 3, 5, 5, 7, 7, 9, 9, 15, 15, 15, 15, 15, 15, 17, 17, 21, 21, 21, 21, 27, 27, 27, 27, 27, 27, 31, 31, 31, 31, 33, 33, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 51, 51, 51, 51, 51, 51, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 65, 65, 73, 73
Offset: 0

Views

Author

Hieronymus Fischer, Feb 15 2012

Keywords

Comments

For n > 0 also the least binary palindrome > n - 1;
a(n+1) is the least binary palindrome > n

Examples

			a(0) = 0 since 0 is the least binary palindrome >= 0;
a(1) = 1 since 1 is the least binary palindrome >= 1;
a(2) = 3 since 3 is the least binary palindrome >= 2;
a(5) = 5 since 5 is the least binary palindrome >= 5;
		

Crossrefs

Sequences related to palindromic floor and ceiling: A175298, A206913, A206914, A261423, A262038, and the large block of consecutive sequences beginning at A265509.

Programs

  • Haskell
    a206914 n = head $ dropWhile (< n) a006995_list
    -- Reinhard Zumkeller, Feb 27 2012

Formula

a(n) = A006995(A206916(n));
a(n) = A006995(A206916(A206913(n-1))+1);
a(n) = A006995(A206915(A206913(n-1))+1);

A265510 a(n) = largest base-2 palindrome m <= 2n+1 such that every base-2 digit of m is <= the corresponding digit of 2n+1; m is written in base 2.

Original entry on oeis.org

1, 11, 101, 111, 1001, 1001, 1001, 1111, 10001, 10001, 10101, 10101, 10001, 11011, 10101, 11111, 100001, 100001, 100001, 100001, 100001, 100001, 101101, 101101, 100001, 110011, 100001, 110011, 100001, 110011, 101101, 111111, 1000001, 1000001, 1000001, 1000001, 1001001, 1001001, 1001001, 1001001, 1000001, 1000001
Offset: 0

Views

Author

N. J. A. Sloane, Dec 09 2015

Keywords

Comments

a(n) = A007088(A265509(n)). - Reinhard Zumkeller, Dec 11 2015

Crossrefs

Sequences related to palindromic floor and ceiling: A175298, A206913, A206914, A261423, A262038, and the large block of consecutive sequences beginning at A265509.
Cf. A007088.

Programs

A265525 a(n) = largest base-10 palindrome m <= n such that every base-10 digit of m is <= the corresponding digit of n.

Original entry on oeis.org

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, 22, 22, 22, 0, 11, 22, 33, 33, 33, 33, 33, 33, 33, 0, 11, 22, 33, 44, 44, 44, 44, 44, 44, 0, 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
Offset: 0

Views

Author

N. J. A. Sloane, Dec 09 2015

Keywords

Crossrefs

Sequences related to palindromic floor and ceiling: A175298, A206913, A206914, A261423, A262038, and the large block of consecutive sequences beginning at A265509.

Programs

  • Haskell
    a265525 n = a265525_list !! n
    a265525_list = f a031298_tabf [[]] where
       f (ds:dss) pss = y : f dss pss' where
         y = foldr (\d v -> 10 * v + d) 0 ys
         (ys:_) = dropWhile (\ps -> not $ and $ zipWith (<=) ps ds) pss'
         pss' = if ds /= reverse ds then pss else ds : pss
    -- Reinhard Zumkeller, Dec 11 2015
  • Maple
    ispal := proc(n) # test for base-b palindrome
    local L, Ln, i;
    global b;
    L := convert(n, base, b);
    Ln := nops(L);
    for i to floor(1/2*Ln) do
    if L[i] <> L[Ln + 1 - i] then return false end if
    end do;
    return true
    end proc
    # find max pal <= n and in base-b shadow of n, write in base 10
    under10:=proc(n) global b;
    local t1,t2,i,m,sw1,L2;
    if n mod b = 0 then return(0); fi;
    t1:=convert(n,base,b);
    for m from n by -1 to 0 do
    if ispal(m) then
    t2:=convert(m,base,b);
    L2:=nops(t2);
    sw1:=1;
    for i from 1 to L2 do
    if t2[i] > t1[i] then sw1:=-1; break; fi;
    od:
    if sw1=1 then return(m); fi;
    fi;
    od;
    end proc;
    b:=10; [seq(under10(n),n=0..144)]; # Gives A265525

A265543 a(n) = smallest base-2 palindrome m >= n such that every base-2 digit of n is <= the corresponding digit of m; m is written in base 2.

Original entry on oeis.org

0, 1, 11, 11, 101, 101, 111, 111, 1001, 1001, 1111, 1111, 1111, 1111, 1111, 1111, 10001, 10001, 11011, 11011, 10101, 10101, 11111, 11111, 11011, 11011, 11011, 11011, 11111, 11111, 11111, 11111, 100001, 100001, 110011, 110011, 101101, 101101, 111111, 111111, 101101, 101101, 111111, 111111, 101101, 101101, 111111
Offset: 0

Views

Author

N. J. A. Sloane, Dec 09 2015

Keywords

Crossrefs

Sequences related to palindromic floor and ceiling: A175298, A206913, A206914, A261423, A262038, and the large block of consecutive sequences beginning at A265509.
See A206913 for the values of m written in base 10.

Programs

  • Maple
    ispal:= proc(n) global b; # test if n is base-b palindrome
      local L, Ln, i;
      L:= convert(n, base, b);
      Ln:= nops(L);
    for i from 1 to floor(Ln/2) do
    if L[i] <> L[Ln+1-i] then return(false); fi;
    od:
    return(true);
    end proc;
    # find min pal >= n and with n in base-b shadow, write in base 10
    over10:=proc(n) global b;
    local t1,t2,i,m,sw1,L1;
    t1:=convert(n,base,b);
    L1:=nops(t1);
    for m from n to 10*n do
    if ispal(m) then
       t2:=convert(m,base,b);
       sw1:=1;
       for i from 1 to L1 do
          if t1[i] > t2[i] then sw1:=-1; break; fi;
                          od:
       if sw1=1 then return(m); fi;
    fi;
                           od;
    lprint("no solution in over10 for n = ", n);
    end proc;
    # find min pal >= n and with n in base-b shadow, write in base 10
    overb:=proc(n) global b;
    local t1,t2,i,m,mb,sw1,L1;
    t1:=convert(n,base,b);
    L1:=nops(t1);
    for m from n to 10*n do
    if ispal(m) then
       t2:=convert(m,base,b);
       sw1:=1;
       for i from 1 to L1 do
          if t1[i] > t2[i] then sw1:=-1; break; fi;
                          od:
       if sw1=1 then mb:=add(t2[i]*10^(i-1), i=1..nops(t2)); return(mb); fi;
    fi;
                           od;
    lprint("no solution in over10 for n = ", n);
    end proc;
    b:=2;
    [seq(over10(n),n=0..144)]; # A175298
    [seq(overb(n),n=0..144)]; # A265543
  • Mathematica
    sb2p[n_]:=Module[{m=n},While[!PalindromeQ[IntegerDigits[m,2]]|| Min[ IntegerDigits[ m,2]-IntegerDigits[n,2]]<0,m++];FromDigits[ IntegerDigits[ m,2]]]; Array[sb2p,50,0] (* Requires Mathematica version 10 or later *) (* Harvey P. Dale, Oct 15 2017 *)

A265558 a(n) = smallest base-10 palindrome m >= n such that every base-10 digit of n is <= the corresponding digit of m.

Original entry on oeis.org

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

Views

Author

N. J. A. Sloane, Dec 10 2015

Keywords

Crossrefs

Sequences related to palindromic floor and ceiling: A175298, A206913, A206914, A261423, A262038, and the large block of consecutive sequences beginning at A265509.
Cf. A265525.

Programs

  • Maple
    For Maple code see A265543.
  • PARI
    a(n,base=10) = { my (d=digits(n,base)); for (k=1, #d\2, d[k]=d[#d+1-k]=max(d[k],d[#d+1-k])); fromdigits(d,base) } \\ Rémy Sigrist, Jun 24 2022

A265511 a(n) = largest base-3 palindrome m <= n such that every base-3 digit of m is <= the corresponding digit of n; m is written in base 10.

Original entry on oeis.org

0, 1, 2, 0, 4, 4, 0, 4, 8, 0, 10, 10, 0, 13, 13, 0, 16, 16, 0, 10, 20, 0, 13, 23, 0, 16, 26, 0, 28, 28, 0, 28, 28, 0, 28, 28, 0, 28, 28, 0, 40, 40, 0, 40, 40, 0, 28, 28, 0, 40, 40, 0, 52, 52, 0, 28, 56, 0, 28, 56, 0, 28, 56, 0, 28, 56, 0, 40, 68, 0, 40, 68, 0, 28, 56, 0, 40, 68, 0, 52, 80, 0, 82, 82, 0, 82, 82, 0, 82
Offset: 0

Views

Author

N. J. A. Sloane, Dec 09 2015

Keywords

Crossrefs

Sequences related to palindromic floor and ceiling: A175298, A206913, A206914, A261423, A262038, and the large block of consecutive sequences beginning at A265509.

Programs

  • Maple
    F:= proc(n) local L;
      L:= convert(n,base,3);
      if L[1] = 0 then return 0 fi;
      add(min(L[i],L[-i])*3^(i-1),i=1..nops(L))
    end proc:
    map(F, [$0..100]); # Robert Israel, Jan 13 2020
Showing 1-10 of 69 results. Next