Skip to content

Instantly share code, notes, and snippets.

@ashaindlin
Last active August 29, 2015 14:04
Show Gist options
  • Save ashaindlin/76ec6e22383233379c67 to your computer and use it in GitHub Desktop.
Save ashaindlin/76ec6e22383233379c67 to your computer and use it in GitHub Desktop.
Thue-Morse sequence generator using horribly inefficient string operations
def thuemorse(n):
b = { "0": "1", "1": "0" }
s = "0"
print "0\t0"
for i in range(1, n+1):
print "{}\t".format(i),
s += ''.join([b[x] for x in s])
print s
if __name__ == '__main__':
thuemorse(6)
0 0
1 01
2 0110
3 01101001
4 0110100110010110
5 01101001100101101001011001101001
6 0110100110010110100101100110100110010110011010010110100110010110
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment