login
In binary representation of n: replace each 0 with 1, and each 1 with 10.
4

%I #49 Nov 04 2024 18:28:13

%S 1,2,5,10,11,22,21,42,23,46,45,90,43,86,85,170,47,94,93,186,91,182,

%T 181,362,87,174,173,346,171,342,341,682,95,190,189,378,187,374,373,

%U 746,183,366,365,730,363,726,725,1450,175,350,349,698,347,694,693,1386

%N In binary representation of n: replace each 0 with 1, and each 1 with 10.

%C All terms are numbers with no two adjacent zeros in binary representation, cf. A003754;

%C a(odd) = even and a(even) = odd;

%C A023416(a(n)) <= A000120(a(n)), equality iff n = 2^k - 1 for k > 0;

%C A055010(n+1) = A196168(A000079(n));

%C A000120(a(n)) = A070939(n);

%C A023416(a(n)) = A000120(n);

%C A070939(a(n)) = A070939(n) + A000120(n).

%H Reinhard Zumkeller, <a href="/A196168/b196168.txt">Table of n, a(n) for n = 0..10000</a>

%H <a href="/index/Bi#binary">Index entries for sequences related to binary expansion of n</a>

%F n = Sum_{i=0..1} b(i)*2^i with 0 <= b(i) <= 1, L >= 0, then a(n) = h(0,L) with h(v,i) = if i > L then v, otherwise h((2*v+1)*(b(i)+1),i-1).

%F From _Jeffrey Shallit_, Oct 28 2021: (Start)

%F a(n) satisfies the recurrences:

%F a(2n+1) = 2*a(2n)

%F a(4n) = -2*a(n) + 3*a(2n)

%F a(8n+2) = -8*a(n) + 8*a(2n) + a(4n+2)

%F a(8n+6) = -4*a(2n) + 5*a(4n+2)

%F which shows that a(n) is a 2-regular sequence. (End)

%e n = 7 -> 111 -> 101010 -> a(7) = 42;

%e n = 8 -> 1000 -> 10111 -> a(8) = 23;

%e n = 9 -> 1001 -> 101110 -> a(9) = 46;

%e n = 10 -> 1010 -> 101101 -> a(10) = 45;

%e n = 11 -> 1011 -> 1011010 -> a(11) = 90;

%e n = 12 -> 1100 -> 101011 -> a(12) = 43.

%t Table[FromDigits[Flatten[IntegerDigits[n,2]/.{{0->1,1->{1,0}}}],2],{n,0,120}] (* _Harvey P. Dale_, Dec 12 2017 *)

%o (Haskell)

%o import Data.List (unfoldr)

%o a196168 0 = 1

%o a196168 n = foldl (\v b -> (2 * v + 1)*(b + 1)) 0 $ reverse $ unfoldr

%o (\x -> if x == 0 then Nothing else Just $ swap $ divMod x 2) n

%o where r v b = (2 * v + 1)*(b+1)

%o (Python)

%o def a(n):

%o b = bin(n)[2:]

%o return int(b.replace('1', 't').replace('0', '1').replace('t', '10'), 2)

%o print([a(n) for n in range(56)]) # _Michael S. Branicky_, Oct 28 2021

%Y Cf. A179888, A005614.

%K nonn

%O 0,2

%A _Reinhard Zumkeller_, Oct 28 2011