GolfScript – 41 (extra credit: 40)
1{.p`n+0:c:P;{:|P=c{c`P|:P!}if):c;}%~1}do
{~.p`n+0:c:P;{:|P=c{c`P|:P!}if):c;}%1}do
What?
The procedure for getting the next number in the sequence: Convert the current number to a string, append a newline and loop over the characters. For each digit, if the previous digit P
is the same, increment the counter c
. Otherwise, add c
and P
to what will be next number, then update these variables. The newline we append allows the last group of digits to be added to the next number.
The exact details can be obtained examining the GolfScript documentation. (Note that |
is used as a variable.)