5 kyu

The Look and Say sequence

828 of 1,137kyushiro

Description:

From Wikipedia:

In mathematics, the look-and-say sequence is the sequence of integers beginning as follows:

1, 11, 21, 1211, 111221, 312211, …

To generate a member of the sequence from the previous member, read off the digits of the previous member, counting the number of digits in groups of the same digit. For example:

1 is read off as "one 1" or 11.
11 is read off as "two 1s" or 21.
21 is read off as "one 2, then one 1" or 1211.
1211 is read off as "one 1, then one 2, then two 1s" or 111221.
111221 is read off as "three 1s, then two 2s, then one 1" or 312211.

Your mission is to write a function which, given an integer "n" as parameter, returns a comma separated list of the first "n" terms of the sequence. For 0, negative, or NaN parameters, -1 shall be returned.

For example:

getLines(2);  //  "1,11"
getLines(3);  //  "1,11,21"
getLines(5);  //  "1,11,21,1211,111221"
get_lines(2);  //  "1,11"
get_lines(3);  //  "1,11,21"
get_lines(5);  //  "1,11,21,1211,111221"
Mathematics
Algorithms

Stats:

CreatedOct 20, 2013
PublishedOct 20, 2013
Warriors Trained2943
Total Skips663
Total Code Submissions5887
Total Times Completed1137
JavaScript Completions828
Swift Completions193
Rust Completions89
Haskell Completions33
Total Stars61
% of votes with a positive feedback rating90% of 176
Total "Very Satisfied" Votes145
Total "Somewhat Satisfied" Votes27
Total "Not Satisfied" Votes4
Ad
Contributors
  • kyushiro Avatar
  • jhoffner Avatar
  • JDeBolt Avatar
  • imjasonmiller Avatar
  • kazk Avatar
  • JohanWiltink Avatar
  • user9644768 Avatar
Ad