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.

A373941 Numbers whose base-2 representation is a "nested" palindrome.

Original entry on oeis.org

0, 1, 3, 7, 15, 21, 31, 45, 63, 73, 127, 153, 255, 273, 341, 443, 511, 561, 693, 891, 1023, 1057, 1453, 1651, 2047, 2145, 2925, 3315, 4095, 4161, 4681, 5461, 5981, 6371, 6891, 7671, 8191, 8385, 9417, 10965, 11997, 12771, 13803, 15351, 16383, 16513, 19609, 21157
Offset: 1

Views

Author

Michael S. Branicky, Jun 23 2024

Keywords

Comments

The definition of "nested" palindrome per A344550 is used: both the right and left halves of the base-2 representation of each term are themselves palindromes. "Half" means ceiling(m/2) for an m-bit term.

Examples

			45 = 101101_2 is a term, since its base-2 representation is a palindrome, and its right half and left half in base-2 are each the palindrome 101.
73 = 1001001_2 is a term, since its base-2 representation is a palindrome, and its right half and left half (both including the center digit) in base-2 are each the palindrome 1001.
		

Crossrefs

Base-2 analog of A344550.
Cf. A373581 (prime terms).

Programs

  • PARI
    isok(k) = my(b=binary(k), b1=Vec(b, ceil(#b/2)), b2=Vec(Vecrev(b), ceil(#b/2))); (Vecrev(b) == b) && (Vecrev(b1) == b1) && (Vecrev(b2) == b2); \\ Michel Marcus, Jun 26 2024
  • Python
    from sympy import isprime
    from itertools import count, islice, product
    def pals(d, base=10): # returns a string
        digits = "".join(str(i) for i in range(base))
        for p in product(digits, repeat=d//2):
            if d//2 > 0 and p[0] == "0": continue
            left = "".join(p); right = left[::-1]
            for mid in [[""], digits][d%2]:
                yield left + mid + right
    def nbp_gen(): # generator of nested binary palindromes (as strings)
        for d in count(2):
            yield from (p+p[-1-d%2::-1] for p in pals((d+1)//2, base=2))
    def agen(): # generator of terms
        yield from [0, 1]
        yield from (int(nbp, 2) for nbp in nbp_gen() if nbp[0] != "0")
    print(list(islice(agen(), 46)))
    
Showing 1-1 of 1 results.