Last active
August 17, 2017 11:06
-
-
Save A1rPun/9966b33c51f2676bffb4bae99094bc41 to your computer and use it in GitHub Desktop.
Thue–Morse sequence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Orginal idea from https://rosettacode.org/wiki/Thue-Morse