DEV Community

Discussion on: Daily Challenge #115 - Look and Say Sequence

Collapse
 
nataliedeweerd profile image
𝐍𝐚𝐭𝐚𝐥𝐢𝐞 𝐝𝐞 𝐖𝐞𝐞𝐫𝐝 • Edited

I completely didn't understand the description here... For those also struggling, here's the explanation from wikipedia for what a "Look and Say sequence" is:

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, one 2, then two 1s" or 111221.
111221 is read off as "three 1s, two 2s, then one 1" or 312211.

Actually, following this, isn't the above code incorrect? In that:

lookAndSaySequence("1", 1) === "1"

should be:

lookAndSaySequence("1", 1) === "11"

As it's "one 1"?

Collapse
 
jbristow profile image
Jon Bristow

I think you're approaching the problem from an array offset point of view (start at 0) where 0 should return the input with no transformations applied. Likewise, 2 would give the result after two iterations.

The problem statement is approaching it from an ordinal perspective. In their view, 1 should be the un-mutated input.

I think they tried to call this out by noting "1": ["1", "11", "21, "1211", "111221", ...], but I agree that it isn't very clear from the text alone.