Code Golf Challenge #1 - Thue-Morse Sequence 08-14-2015, 05:09 PM
#1
What is code golf?
Code golfing is an activity where a bunch of people compete to complete a specific programming task, using as few bytes of code as possible to complete the task.
Now, onto the challenge!
Thue-Morse Sequence
In mathematics, the Thue–Morse sequence, or Prouhet–Thue–Morse sequence, is the binary sequence (an infinite sequence of 0s and 1s) obtained by starting with 0 and successively appending the Boolean complement of the sequence obtained thus far. The first few steps of this procedure yield the strings 0 then 01, 0110, 01101001, 0110100110010110, and so on, which are prefixes of the Thue–Morse sequence. The full sequence begins:
This is sequence A010060 in OEIS.
The Challenge
You should create a program or function which takes input via some method (standard input, function parameters, etc) which will produce the first n characters in the Thue-Morse sequence. You are not allowed to hardcode the sequence into your program, as it should theoretically work for any value of n. You cannot use any external sources to obtain the digits, all of them must be calculated one the program is run. You should not plagiarize existing programs. Breaking any of these rules disqualifies your program.
Once you have written your program, it would be extremely helpful if you could post a link to http://repl.it or http://ideone.com , which are online code compilers for a bunch of languages. This is so I can test and make sure that it functions as it should.
Also, you must start out your post saying which language and version you are using, and the byte count, which can be obtained from here. If you are missing this, I will not count your score until you add it!
The challenge will run for 1 week, while I can still edit the main post. After that, the shortest answer that has not been disqualified will be crowned the winner, and the user will receive 84 NSP.
Example Input/Output
Output can be in the format of a list/array, string or binary sequence.
Leaderboard
Donate
If you'd like to increase the size of the prize pool, donate and I'll increase the size!
Thanks to @Eclipse for donating 25 NSP, and @Panty for donating 39 NSP!
Code golfing is an activity where a bunch of people compete to complete a specific programming task, using as few bytes of code as possible to complete the task.
Now, onto the challenge!
Thue-Morse Sequence
In mathematics, the Thue–Morse sequence, or Prouhet–Thue–Morse sequence, is the binary sequence (an infinite sequence of 0s and 1s) obtained by starting with 0 and successively appending the Boolean complement of the sequence obtained thus far. The first few steps of this procedure yield the strings 0 then 01, 0110, 01101001, 0110100110010110, and so on, which are prefixes of the Thue–Morse sequence. The full sequence begins:
Code:
01101001100101101001011001101001100101100110100101101001100101101001011001101001This is sequence A010060 in OEIS.
The Challenge
You should create a program or function which takes input via some method (standard input, function parameters, etc) which will produce the first n characters in the Thue-Morse sequence. You are not allowed to hardcode the sequence into your program, as it should theoretically work for any value of n. You cannot use any external sources to obtain the digits, all of them must be calculated one the program is run. You should not plagiarize existing programs. Breaking any of these rules disqualifies your program.
Once you have written your program, it would be extremely helpful if you could post a link to http://repl.it or http://ideone.com , which are online code compilers for a bunch of languages. This is so I can test and make sure that it functions as it should.
Also, you must start out your post saying which language and version you are using, and the byte count, which can be obtained from here. If you are missing this, I will not count your score until you add it!
The challenge will run for 1 week, while I can still edit the main post. After that, the shortest answer that has not been disqualified will be crowned the winner, and the user will receive 84 NSP.
Example Input/Output
Output can be in the format of a list/array, string or binary sequence.
Code:
n = 6 --> [0,1,1,0,1,0]
n = 20 --> '01101001100101101001'
n = 1 --> 0
n = 0 -->
n = 99 --> 011010011001011010010110011010011001011001101001011010011001011010010110011010010110100110010110011Leaderboard
Code:
User | Language | Bytes
-----------------------------------------------
Stocking | Python 2 | 79
Stocking | Node.js | 100
eclipse | Python 2 | 119Donate
If you'd like to increase the size of the prize pool, donate and I'll increase the size!

Thanks to @Eclipse for donating 25 NSP, and @Panty for donating 39 NSP!
![[Image: CDUAq9d.png]](http://i.imgur.com/CDUAq9d.png)





![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)








![[Image: dHJ4Beo.gif]](http://i.imgur.com/dHJ4Beo.gif)








To be fair, I have practice golfing, you don't