A303769 a(0) = 0, a(n+1) is either the largest number obtained from a(n) by toggling a single 1-bit off (to 0) if no such number is yet in the sequence, otherwise the least number not yet in sequence that can be obtained from a(n) by toggling a single 0-bit on (to 1). In both cases the bit to be toggled is the rightmost possible that results yet an unencountered number.
0, 1, 3, 2, 6, 4, 5, 7, 15, 14, 12, 8, 9, 11, 10, 26, 24, 16, 17, 19, 18, 22, 20, 21, 23, 31, 30, 28, 29, 25, 27, 59, 58, 56, 48, 32, 33, 35, 34, 38, 36, 37, 39, 47, 46, 44, 40, 41, 43, 42, 106, 104, 96, 64, 65, 67, 66, 70, 68, 69, 71, 79, 78, 76, 72, 73, 75, 74, 90, 88, 80, 81, 83, 82, 86, 84, 85, 87, 95, 94, 92, 93, 89, 91, 123, 122, 120, 112, 113, 97, 99
Offset: 0
Links
Crossrefs
Programs
-
Mathematica
Nest[Append[#1, Min@ Select[{#2, #3, 2^IntegerLength[Last@ #1, 2] + Last@ #1}, IntegerQ]] & @@ Function[{a, d}, {a, SelectFirst[Sort@ Map[FromDigits[ReplacePart[d, First@ # -> 1], 2] &, Position[d, 0]], FreeQ[a, #] &], SelectFirst[Sort[#, Greater] &@ Map[FromDigits[ReplacePart[d, First@ # -> 0], 2] &, Position[d, 1]], FreeQ[a, #] &]}] @@ {#, IntegerDigits[Last@ #, 2]} &, {0}, 90] (* Michael De Vlieger, Jun 11 2018 *)
-
PARI
prepare_v303769(up_to) = { my(v = vector(up_to), occurred = Map(), prev=0, b); mapput(occurred,0,0); for(n=1,up_to, b=1; while(b<=prev, if(bitand(prev,b) && !mapisdefined(occurred,prev-b), v[n] = prev-b; break, b <<= 1)); if(!v[n], b=1; while(bitand(prev,b) || mapisdefined(occurred,prev+b), b <<= 1); v[n] = prev+b); mapput(occurred,prev = v[n],n)); (v); }; v303769 = prepare_v303769(16384); A303769(n) = if(!n,n,v303769[n]); \\ Antti Karttunen, Jun 08 2018
Formula
From David A. Corneth, May 05 2018: (Start)
Comments