Skip to content

Instantly share code, notes, and snippets.

@A1rPun
Last active August 17, 2017 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save A1rPun/9966b33c51f2676bffb4bae99094bc41 to your computer and use it in GitHub Desktop.
Save A1rPun/9966b33c51f2676bffb4bae99094bc41 to your computer and use it in GitHub Desktop.
Thue–Morse sequence
function thueMorse(i) {
var a = '0', b = '1';
for (; i--;)
a += [b, b += a][0];
return a;
}
thueMorse(0); // 0
thueMorse(1); // 01
thueMorse(4); // 0110100110010110
thueMorse(6); // 0110100110010110100101100110100110010110011010010110100110010110
function thueMorse2(i, a = '0', b = '1') {
for (; i--;)
a += [b, b += a][0];
return a;
}
thueMorse2(2, 'A', 'B'); // ABBA
@A1rPun
Copy link
Author

A1rPun commented Aug 17, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment