login
a(n) = (a(n-2) XOR A030101(a(n-1))) + 1, a(0) = 0, a(1) = 1.
1

%I #64 Oct 31 2022 05:55:05

%S 0,1,2,1,4,1,6,3,6,1,8,1,10,5,16,5,22,9,32,9,42,29,62,3,62,29,42,9,36,

%T 1,38,25,54,3,54,25,38,1,40,5,46,25,62,7,58,17,44,29,60,19,38,11,44,7,

%U 44,11,34,27,58,13,50,31,46,3,46,31,50,13,58,27,34

%N a(n) = (a(n-2) XOR A030101(a(n-1))) + 1, a(0) = 0, a(1) = 1.

%C Is this sequence periodic? The related sequence A114375 was found to be nonperiodic, however the same argument does not hold here as the bitreversal operation used here maps different values onto the same. E.g. 111000 -> 111 111 -> 111. Every time this sequence develops a not yet seen value a(n) = 2^m, the space of combinations increases from (2^(m-1))^2 to (2^m)^2 reducing the probability to hit an already seen pair of values for [a(n-2),a(n-1)].

%C This sequence contains some palindromic parts. Example a(55)..a(72): 11, 34, 27, 58, 13, 50, 31, 46, 3, 46, 31, 50, 13, 58, 27, 34, 11.

%C a(n) <> a(n-1). a(2k) = 2m. a(2k+1) = 2m+1.

%C a(n) = 2^k, k > 0 for each k will exist only once in this sequence, if it is never periodic. In this case the 2^k will be in increasing sequence ordered.

%C Conjecture: Let p be an odd number, then a(n) = p will be more frequently found in this sequence than a(n) = p+1 (tested for n = 0..10^7 with primes > 2, but seems to be true for all odd too).

%H Robert Israel, <a href="/A339602/b339602.txt">Table of n, a(n) for n = 0..10000</a>

%H Thomas Scheuerle, <a href="/A339602/a339602.png">Interesting staircase pattern in this sequence</a>.

%e a(5) = 1 binary: 1; a(6) = 6 binary: 110, binary bitreversed: 11;

%e so a(7) = binary: (001 XOR 11)+1 = 11 decimal: 3.

%p bitrev:= proc(n) local L,i;

%p L:= convert(n,base,2);

%p add(L[-i]*2^(i-1),i=1..nops(L))

%p end proc:

%p A:= Array(0..100):

%p A[0]:= 0: A[1]:= 1:

%p for n from 2 to 100 do

%p A[n]:= Bits:-Xor(A[n-2],bitrev(A[n-1]))+1

%p od:

%p seq(A[i],i=0..100); # _Robert Israel_, Dec 25 2020

%t f[n_] := FromDigits[Reverse @ IntegerDigits[n, 2], 2]; a[0] = 0; a[1] = 1; a[n_] := a[n] = BitXor[a[n - 2], f[a[n - 1]]] + 1; Array[a, 100, 0] (* _Amiram Eldar_, Dec 10 2020 *)

%o (MATLAB)

%o function a = calc_A339602(length)

%o % a(0) = 0 not in output of program

%o a(1) = 1; % part of definition

%o an_2 = 0; % a(0)

%o an_1 = a(1);

%o for n = 2:length

%o an_1_old = an_1;

%o an_1 = bitxor(an_2,bitreverse(an_1))+1;

%o an_2 = an_1_old;

%o a(n) = an_1;

%o end

%o end

%o function r = bitreverse(k) % A030101(k)

%o r = 0;

%o m = floor(log2(k))+1;

%o for i = 1:m

%o r = bitset(r,m-i+1,bitget(k,i));

%o end

%o end

%o (PARI) f(n) = fromdigits(Vecrev(binary(n)), 2); \\ A030101

%o lista(nn) = {my(x=0, y=1); print1(x, ", ", y, ", "); for (n=2, nn, z = bitxor(x, f(y)) +1; print1(z, ", "); x = y; y = z;);} \\ _Michel Marcus_, Dec 10 2020

%Y Cf. A030101, A114375.

%K nonn,base,look

%O 0,3

%A _Thomas Scheuerle_, Dec 09 2020