login
Take n in binary. Rotate the binary digits to the left until a 1 once again appears as the leftmost digit. Convert back into decimal for a(n).
8

%I #64 Apr 27 2024 14:12:40

%S 1,2,3,4,6,5,7,8,12,10,14,9,11,13,15,16,24,20,28,18,22,26,30,17,19,21,

%T 23,25,27,29,31,32,48,40,56,36,44,52,60,34,38,42,46,50,54,58,62,33,35,

%U 37,39,41,43,45,47,49,51,53,55,57,59,61,63,64,96,80,112,72,88,104,120

%N Take n in binary. Rotate the binary digits to the left until a 1 once again appears as the leftmost digit. Convert back into decimal for a(n).

%C This sequence written in binary is A139709.

%C This is a permutation of the positive integers. A139706 is the inverse permutation.

%C Moreover, the first 2^n terms are a permutation of the first 2^n positive integers. Fixed points of the permutation are A272919. - _Ivan Neretin_, May 10 2016

%D Lionel Levine, Fractal sequences and restricted Nim, Ars Combin. 80 (2006), 113-127.

%H Ivan Neretin, <a href="/A139708/b139708.txt">Table of n, a(n) for n = 1..8192</a>

%H Lionel Levine, <a href="https://arxiv.org/abs/math/0409408">Fractal sequences and restricted Nim</a>, arXiv:math/0409408 [math.CO], 2004.

%H <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>

%F From _Mikhail Kurkov_, Dec 23 2023: (Start)

%F a(2^m + k) = f(2^m + f(k)) for m >= 0, 0 <= k < 2^m where f(n) = A059893(n) for n > 0 with f(0) = 0.

%F a(n) = f(A139706(f(n))). (End)

%p A139708 := proc(n) local a; a := ListTools[Rotate](convert(n,base,2),-1) ; while op(-1,a) = 0 do a := ListTools[Rotate](a,-1) ; od: add(op(i,a)*2^(i-1),i=1..nops(a)) : end: seq(A139708(n),n=1..100) ; # _R. J. Mathar_, May 04 2008

%t rbd[n_]:=Module[{idn2=RotateLeft[IntegerDigits[n,2]]},While[ idn2[[1]] ==0, idn2= RotateLeft[ idn2]];FromDigits[idn2,2]]; Array[rbd,80] (* _Harvey P. Dale_, Jun 07 2015 *)

%t Table[FromDigits[RotateLeft[d = IntegerDigits[n, 2], Position[Join[d, d], 1][[2, 1]] - 1], 2], {n, 71}] (* _Ivan Neretin_, May 10 2016 *)

%o (PARI) a(n) = if(bitand(n,n-1)==0, n, my(b=logint(n,2), s=b-logint(n-(1<<b),2)); (((n - (1<<b)) << 1) + 1) << (s-1)) \\ _Andrew Howroyd_, Jan 04 2024

%Y Cf. A139706 (inverse), A139709 (in binary), A272919 (fixed points).

%K nonn,base,look,easy

%O 1,2

%A _Leroy Quet_, Apr 30 2008

%E More terms from _R. J. Mathar_, May 04 2008