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"
Mathematics
Algorithms
Similar Kata:
Stats:
Created | Oct 20, 2013 |
Published | Oct 20, 2013 |
Warriors Trained | 2943 |
Total Skips | 663 |
Total Code Submissions | 5887 |
Total Times Completed | 1137 |
JavaScript Completions | 828 |
Swift Completions | 193 |
Rust Completions | 89 |
Haskell Completions | 33 |
Total Stars | 61 |
% of votes with a positive feedback rating | 90% of 176 |
Total "Very Satisfied" Votes | 145 |
Total "Somewhat Satisfied" Votes | 27 |
Total "Not Satisfied" Votes | 4 |