8
For those who are not familiarized with the Pea Pattern, it is a simple mathematical pattern.
There are multiple variations of this pattern, but we will focus in one:
Ascending Pea Pattern
It looks like this:
1
11
21
1112
3112
211213
...
It seems really hard to get the following line, but it is really easy. The way to get the next line is by counting the number of times a digit have repeated on the previous line (start counting with the lowest, to largest):
one
one one
two ones
one one, one two
three ones, one two
two ones, one two, one three
...
Requirements/Rules:
- We will start at
1
- It will be a snippet
- There must be a way to specify the number of lines generates (e.g
5
will give the first 5 lines) - The code should be as short as possible
- It must start counting from lowest to largest (the Ascending variation)
I am new here, please tell me how can I improve. For example, should I specify a date limit? – ajax333221 – 2012-01-14T18:43:50.280
1You could specify whether you want a full program with I/O or a snippet is enough (or if you don't care.) But it looks well-specified enough at first glance. – J B – 2012-01-14T19:10:11.230
@JB Thanks for your enlightening words. I have updated my post – ajax333221 – 2012-01-14T19:54:40.753
Related: http://codegolf.stackexchange.com/questions/2323/look-and-say-sequence
– Joey Adams – 2012-01-15T02:00:26.783The 13th iteration, and all subsequent iterations, are
21322314
. Is this correct? – Joey Adams – 2012-01-15T02:15:51.080@JoeyAdams That's what I get, and the wiki page linked above seems to confirm it. – Gareth – 2012-01-15T02:19:13.753