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)
21322314
. Is this correct? \$\endgroup\$ – Joey Adams Jan 15 '12 at 2:15