# Write a "Look-and-Say Numbers" generator [duplicate]

There is a sequence of numbers called the "Look-and-Say Numbers".

Here is an example of the first 5 terms of the sequence, starting at 1 (with spaces added between the digits):

     1
1 1
2 1
1 2 1 1
1 1 1 2 2 1


The pattern is simple, once you see it.

The sequence starts with 1. There is one 1, so the next number is 11 (as in one of the number 1).

In this number, there are 2 1s, so the next number is 21.

In this number there is 1 2, and 1 1, so the next number is 1211.

In this number there is 1 1, followed by 1 2, followed 2 1s - so the number is 111221.

You must write a program that generates the first n terms of this sequence, where n is given by stdin. The sequence will start at 1.

This is a code-golf task, so shortest code wins.

• @Calvin'sHobbies The linked question has an additional restriction, but that restriction is quite trivial in practice. Therefore I am voting to close as a duplicate. Aug 12 '14 at 11:59

## Mathematica, 68 bytes

There's no STDIN in Mathematica, so here is a function instead

s=FromDigits/@NestList[Flatten[Reverse@@@Tally/@Split[#]]&,{1},#-1]&


Usage:

s[5]

> {1, 11, 21, 1211, 111221}

• Isn't Input[] STDIN? Aug 12 '14 at 13:01
• @DavidCarraher Well, it's kinda STDIN but parses and interprets the input right away, right? Aug 12 '14 at 13:02
• Good point. And InputString[] avoids parsing but interprets all input as strings. Aug 12 '14 at 13:22