OFFSET
1,2
COMMENTS
This sequence exactly contains those positive integers in A006995 (positive binary palindromes) together with the terms of A035928 (those positive integers n where reversing the order of the binary digits produces the binary complement of n). - Leroy Quet, Sep 14 2009
Also the indices of the compositions that are palindromic. For the definition of the index of a composition see A298644. For example, 93 is in the sequence since its binary form is 1011101 and the composition [1,1,3,1,1] is palindromic. On the other hand, 132 is not in the sequence since its binary form is 10000100 and the composition [1,4,1,2] is not palindromic. The command c(n) from the Maple program yields the composition having index n. - Emeric Deutsch, Jan 28 2018
LINKS
Rémy Sigrist, Table of n, a(n) for n = 1..10000
MAPLE
Runs:=proc(L) local j, r, i, k:j:=1: r[j]:=L[1]: for i from 2 to nops(L) do if L[i]=L[i-1] then r[j]:=r[j], L[i] else j:=j+1: r[j]:=L[i] end if end do: [seq([r[k]], k=1..j)] end proc: RunLengths:=proc(L) map(nops, Runs(L)) end proc: c:=proc(n) ListTools:-Reverse(convert(n, base, 2)): RunLengths(`%`) end proc: A:={}: for n from 1 to 500 do crev(n):=[seq(c(n)[1+ nops(c(n))-j], j=1..nops(c(n)))] od: for n from 1 to 500 do if c(n)=crev(n) then A:=A union {n} else fi od: A; # most of the Maple program is due to W. Edwin Clark. # Emeric Deutsch, Jan 28 2018
MATHEMATICA
Position[Array[Length /@ Split@ IntegerDigits[#, 2] &, 400], _? PalindromeQ, 1] // Flatten (* Michael De Vlieger, Jan 28 2018 *)
PROG
(PARI) ispal(v) = {for(i=1, #v\2, if (v[i] != v[#v-i+1], return(0)); ); return(1); }
isok(n) = {b = binary(n); lastb = b[1]; vrun = vector(1); vrun[1] = 1; for (i=2, #b, if (b[i] != lastb, vrun = concat(vrun, 1); lastb = b[i]; , vrun[#vrun]++; )); return (ispal(vrun)); } \\ Michel Marcus, Jul 10 2013
CROSSREFS
KEYWORD
nonn,base
AUTHOR
STATUS
approved