Search⌘ K

Look-and-Say Sequence

Understand how to generate the Look and Say sequence by reading digits and counting groups within a string. Learn the Python implementation that processes sequences step-by-step, enabling you to manipulate and generate terms based on consecutive digits. This lesson helps you grasp string traversal and grouping concepts essential for complex string processing tasks.

We'll cover the following...

In this lesson, we will be considering the so-called “Look-and-Say” sequence. The first few terms of the sequence are:

1, 11, 21, 1211, 111221, 312211, 13112221, 1113213211, ... 

To generate a member of the sequence from the previous member, read off the digits of the previous member and record the count of the number of digits in groups of the same digit.

For example, 1 is read off as one 1 which implies that the count of 1 is one. As 1 is read off as “one 1”, the next sequence will be written as 11 where 1 replaces one. Now 11 is read off as “two 1s” as the count of “1” is two in this term. Hence, the next ...