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.

A118594 Palindromes in base 3 (written in base 3).

Original entry on oeis.org

0, 1, 2, 11, 22, 101, 111, 121, 202, 212, 222, 1001, 1111, 1221, 2002, 2112, 2222, 10001, 10101, 10201, 11011, 11111, 11211, 12021, 12121, 12221, 20002, 20102, 20202, 21012, 21112, 21212, 22022, 22122, 22222, 100001, 101101, 102201, 110011, 111111, 112211, 120021
Offset: 1

Views

Author

Martin Renner, May 08 2006

Keywords

Comments

The number of n-digit terms is given by A225367. - M. F. Hasler, May 05 2013 [Moved here on May 08 2013]
Digit-wise application of A000578 (and also superposition of a(n) with its horizontal OR vertical reflection) yields A006072. - M. F. Hasler, May 08 2013
Equivalently, palindromes k (written in base 10) such that 4*k is a palindrome. - Bruno Berselli, Sep 12 2018

Crossrefs

Programs

  • Mathematica
    (* get NextPalindrome from A029965 *) Select[NestList[NextPalindrome, 0, 1110], Max@IntegerDigits@# < 3 &] (* Robert G. Wilson v, May 09 2006 *)
    Select[FromDigits/@Tuples[{0,1,2},8],IntegerDigits[#]==Reverse[ IntegerDigits[ #]]&] (* Harvey P. Dale, Apr 20 2015 *)
  • PARI
    {for(l=1,5,u=vector((l+1)\2,i,10^(i-1)+(2*i-11&&i==1,2]), print1(v*u",")))} \\ The n-th term could be produced by using (partial sums of) A225367 to skip all shorter terms, and then skipping the adequate number of vectors v until n is reached.  - M. F. Hasler, May 08 2013
    
  • Python
    from itertools import count, islice, product
    def agen(): # generator of terms
        yield from [0, 1, 2]
        for d in count(2):
            for start in "12":
                for rest in product("012", repeat=d//2-1):
                    left = start + "".join(rest)
                    for mid in [[""], ["0", "1", "2"]][d%2]:
                        yield int(left + mid + left[::-1])
    print(list(islice(agen(), 42))) # Michael S. Branicky, Mar 29 2022
    
  • Python
    from sympy import integer_log
    from gmpy2 import digits
    def A118594(n):
        if n == 1: return 0
        y = 3*(x:=3**integer_log(n>>1,3)[0])
        return int((s:=digits(n-x,3))+s[-2::-1] if nChai Wah Wu, Jun 14 2024
  • Sage
    [int(n.str(base=3)) for n in (0..757) if Word(n.digits(3)).is_palindrome()] # Peter Luschny, Sep 13 2018
    

Extensions

More terms from Robert G. Wilson v, May 09 2006
a(40) and beyond from Michael S. Branicky, Mar 29 2022