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-1 of 1 results.

A357044 Lexicographic earliest sequence of distinct palindromes (A002113) such that a(n)+a(n+1) is never palindromic.

Original entry on oeis.org

1, 9, 3, 7, 5, 8, 2, 11, 4, 6, 22, 88, 44, 66, 77, 33, 99, 55, 101, 909, 111, 191, 121, 181, 131, 171, 141, 161, 151, 252, 262, 242, 272, 232, 282, 222, 292, 212, 393, 313, 494, 323, 383, 333, 373, 343, 363, 353, 454, 464, 444, 474, 434, 484, 424
Offset: 1

Views

Author

Eric Angelini and M. F. Hasler, Sep 14 2022

Keywords

Comments

Obviously the sequence cannot contain 0.
It is easy to prove that the sequence is a permutation of the nonzero palindromes (in the sense that it contains each of them exactly once).

Crossrefs

Cf. A002113 (palindromes), A029742 (non-palindromes), A262038 (next palindrome), A357045 (non-palindromes with palindromic sum of neighbors).

Programs

  • PARI
    A357044_first(n, U=[0], a=9)={vector(n,k, k=U[1]; while(is_A002113(a+k=A262038(k+1)) || setsearch(U, k), ); U=setunion(U,[a=k]); while(#U>1 && U[2]==A262038(U[1]+1), U=U[^1]); a)}
    
  • Python
    from itertools import count, islice
    def ispal(n): s = str(n); return s == s[::-1]
    def nextpal(p): # next largest palindrome after palindrome p
        d = str(p)
        if set(d) == {'9'}: return int('1' + '0'*(len(d)-1) + '1')
        h = str(int(d[:(len(d)+1)//2]) + 1)
        return int(h + h[:-1][::-1]) if len(d)&1 else int(h + h[::-1])
    def agen():
        aset, pal, minpal = {1}, 1, 2
        while True:
            an = pal; yield an; aset.add(an); pal = minpal
            while pal in aset or ispal(an+pal): pal = nextpal(pal)
            while minpal in aset: minpal = nextpal(minpal)
    print(list(islice(agen(), 55))) # Michael S. Branicky, Sep 14 2022
Showing 1-1 of 1 results.