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

A216264 Number of rich binary words of length n.

Original entry on oeis.org

1, 2, 4, 8, 16, 32, 64, 128, 252, 488, 932, 1756, 3246, 5916, 10618, 18800, 32846, 56704, 96702, 163184, 272460, 450586, 738274, 1199376, 1932338, 3089518, 4903164, 7728120, 12099440, 18825066, 29112876, 44767202, 68461866, 104153666, 157657852, 237510110, 356158688
Offset: 0

Views

Author

Jeffrey Shallit, Mar 15 2013

Keywords

Comments

A word of length n is "rich" if it contains, as subwords, exactly n + 1 distinct palindromes (including the empty word). Here "subword" means contiguous subsequence of the word.

Examples

			For n = 8 we have a(n) = 2^8 - 4 = 252 because the only non-rich words are 00101100, 00110100, and their complements.
		

Crossrefs

Cf. A225681.

Programs

  • Mathematica
    (* Program not suitable to compute a large number of terms *)
    richQ[w_] := (w[[#[[1]] ;; #[[2]]]]& /@ SequencePosition[w, _?PalindromeQ] // Union // Length) == n+1;
    a[n_] := a[n] = Select[PadLeft[IntegerDigits[#, 2], n]& /@ Range[0, 2^n-1], richQ] // Length; Table[Print["a(", n, ") = ", a[n]]; a[n], {n, 0, 16}] (* Jean-François Alcover, Sep 22 2018 *)
  • PARI
    ispal(v) = {for (i=1, #v\2, if (v[i] != v[#v-i+1], return(0)); ); return(1); };
    isrich(vb, n) = {pals = Set(); for (i=1, #vb, for (len=1, #vb-i+1, subword = vector(len, x, vb[i+x-1]); if (ispal(subword), pals = setunion(pals, Set(Str(subword)) ); ); ); ); if (length(pals)==n, return(1)); return (0); }
    a(n) = {nbr = 0; for (i=0, 2^n-1, vb = binary(i); while(length(vb) < n, vb = concat(0, vb); ); if (isrich(vb, n), nbr++); ); return (nbr); } \\ Michel Marcus, May 26 2013
    
  • Python
    from itertools import product
    def pal(w): return w == w[::-1]
    def rich(w):
        subs = (w[i:j] for i in range(len(w)) for j in range(i+1, len(w)+1))
        return len(w) == sum(pal(s) for s in set(subs))
    def a(n):
        if n == 0: return 1
        return sum(2 for b in product("01", repeat=n-1) if rich("0"+"".join(b)))
    print([a(n) for n in range(16)]) # Michael S. Branicky, Jul 07 2022

Extensions

a(17) from Alois P. Heinz, Mar 15 2013
a(18)-a(25) from Jeffrey Shallit, Mar 19 2013
a(26)-a(60) from Mikhail Rubinchik, Mar 05 2015

A348664 Numbers whose binary expansion is not rich.

Original entry on oeis.org

203, 211, 300, 308, 333, 357, 395, 406, 407, 419, 422, 423, 459, 467, 556, 564, 600, 601, 604, 616, 617, 628, 653, 666, 667, 669, 690, 709, 714, 715, 723, 741, 779, 787, 790, 791, 803, 811, 812, 813, 814, 815, 820, 835, 838, 839, 844, 845, 846, 847, 851, 869
Offset: 1

Views

Author

Rémy Sigrist, Oct 28 2021

Keywords

Comments

A word of length k is "rich" if it contains, as contiguous subsequences, exactly k + 1 distinct palindromes (including the empty word).
There are A225681(k)/2 terms with k binary digits.

Examples

			For n = 203:
- the binary expansion of 203 is "11001011" and has 8 binary digits,
- we have the following 8 palindromes: "", "0", "1", "00", "11", "010", "101", "1001"
- so 203 is not rich, and belongs to this sequence.
For n = 204:
- the binary expansion of 204 is "11001100" and has 8 binary digits,
- we have the following 9 palindromes: "", "0", "1", "00", "11", "0110", "1001", "001100", "110011"
- so 204 is rich, and does not belong to this sequence.
		

Crossrefs

Programs

  • Mathematica
    Select[Range@1000,Length@Select[Union[Subsequences[s=IntegerDigits[#,2]]],PalindromeQ]<=Length@s&] (* Giorgos Kalogeropoulos, Oct 29 2021 *)
  • PARI
    is(n) = { my (b=binary(n), p=select(w->w==Vecrev(w), setbinop((i,j)->b[i..j],[1..#b]))); #b!=#p }
    
  • Python
    def ispal(s): return s == s[::-1]
    def ok(n):
      s = bin(n)[2:]
      return len(s) >= 1 + len(set(s[i:j] for i in range(len(s)) for j in range(i+1, len(s)+1) if ispal(s[i:j])))
    print([k for k in range(870) if ok(k)]) # Michael S. Branicky, Oct 29 2021

Formula

{k: A137397(k) <= A070939(k)}. - Michael S. Branicky, Oct 29 2021
Showing 1-2 of 2 results.