OFFSET
0,4
COMMENTS
LINKS
Alois P. Heinz, Table of n, a(n) for n = 0..65535
EXAMPLE
For n = 18, a(n-1) = 8. That is the second 8 in the sequence. We cannot toggle the 1-bit, because that was already used to derive a(16) = 9 from a(15) = 8, so instead we toggle the 2-bit, yielding a(n) = 10.
MAPLE
a:= proc() local b, a; b:= proc() 1/2 end; a:= proc(n)
option remember; local h; if n=0 then 0 else h:=
a(n-1); b(h):= 2*b(h); Bits[Xor](h, b(h)) fi end
end():
seq(a(n), n=0..127); # Alois P. Heinz, Dec 05 2020
MATHEMATICA
a[m_] := Module[{b, a}, b[_] = 1/2; a[n_] := a[n] =
Module[{h}, If[n == 0 , 0 , h = a[n - 1];
b[h] = 2*b[h]; BitXor[h, b[h]]]]; a[m]];
Table[a[n], {n, 0, 127}] (* Jean-François Alcover, May 15 2022, after Alois P. Heinz *)
CROSSREFS
KEYWORD
easy,nonn
AUTHOR
Allan C. Wechsler, Dec 05 2020
STATUS
approved