22
4
Definition1
A Kolakoski sequence is a self-describing infinite sequence {kn} of alternating blocks of 1's and 2's, given by the following rules:
- k0 = 1
- kn = the length of the (n+1)'th block
The Task
Given a positive integer n
, generate the first n
elements of the Kolakoski sequence.
Details
Input will be provided as a single command line argument n
. Please write a full program that will print the first n
elements of the Kolakoski sequence (in order) to STDOUT, with each element separated by your favorite whitespace.
Scoring
Lets count source code bytes this time with all whitespace included. Fewest number of bytes wins. In the event of a tie, the solution with the earliest submission time wins.
The Sequence2
1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2, 1, 1, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 1, 1, 2, 2, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2, 1, 1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2, 1, 1, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, ...
References
- John Smith, Ariel Scolnicov, yark. "Kolakoski sequence" (version 3). PlanetMath.org. Freely available at http://planetmath.org/KolakoskiSequence.html.
- The Online Encyclopedia of Integer Sequences http://oeis.org/A000002
Other resources
- Kolakoski Sequence at Wikipedia http://en.wikipedia.org/wiki/Kolakoski_sequence
- Kolakoski Sequence at Wolfram MathWorld http://mathworld.wolfram.com/KolakoskiSequence.html
Any particular reason
n
is command line arg? – CalculatorFeline – 2016-04-01T15:19:12.383@CatsAreFluffy not originally, but i'll happily keep any requirement that adds a few irritating chars to the golf-oriented languages :) – ardnew – 2016-04-01T16:35:05.620
That's a cumbersome I/O format that makes many languages unable to participate.
– Mego – 2016-04-02T05:26:06.527@Mego thanks for the tip. but in fairness to the current submissions, let's not go changing preferential specs on a 4 year old question – ardnew – 2016-04-02T20:01:24.707
@ardnew I'm not saying to change it. I'm just saying it's not a good idea. – Mego – 2016-04-02T20:03:10.933
11
Note: reposting this question is being discussed on meta.
– Peter Taylor – 2018-02-21T16:49:03.720