New Order #2: Turn My Way
JavaScript (ES6), 65 bytes
1-indexed.
n=>{for(o=p=[k=1];o[k]|~-(i=p^k)&i?k++:k=o[p=k]=!!n--;);return p}
Try it online!
Commented
n => { // n = index of requested term
for( // for loop:
o = // o = storage object for the terms of the sequence
p = // p = last term found in the sequence
[k = 1]; // k = current term
o[k] | // if k was already encountered
~-(i = p ^ k) & i ? // or (p XOR k) has more than 1 bit set:
k++ // increment k
: // else:
k = o[p = k] // set o[k], set p to k
= !!n--; // stop if n is equal to 0 or set k to 1; decrement n
); // end of for()
return p // return p
} // end
Jelly, 26 20 bytes
ṀBLŻ2*^1ị$ḟ⁸Ṃ;
0Ç⁸¡Ḣ
Try it online!
A full program that takes n as the single argument. Works for all test cases. Also note that, although not required, it handles n=0.
Explanation
Helper link: find next term and prepend
Ṁ | maximum of list so far
B | convert to binary
L | number of binary digits
Ż | 0..above number
2* | 2 to the power of each of the above
^ | exclusive or with...
1ị$ | ... the most recent term in the list so far
ḟ⁸ | filter out anything used already
Ṃ | find the minimum
; | prepend to existing list
Main link
0 | start with zero
Ç | call the above link
⁸¡ | and repeat n times
Ḣ | take the last term added
Java (JDK), 142 138 124 123 132 130 98 bytes
- increased to account for import, saved a byte thanks to @kevin-cruijssen
- switched collection to int array thanks to @olivier-grégoire
n->{int s[]=new int[9*n],j,k=0;for(;n-->0;s[k=j]++)for(j=0;s[++j]>0|n.bitCount(j^k)>1;);return k;}
Try it online!