#282 · Strings · Intermediate · 65 XP · about 12 min
Read the digits 1211 out loud, describing each group of equal digits: "one 1, one 2, two 1s". Write that down as digits and you get 111221. Doing this again and again, starting from 1, gives the look-and-say sequence: 1, 11, 21, 1211, 111221, 312211, and so on.
Write look_and_say(seed, steps) that starts from the string seed, applies the read-aloud step steps times and returns the result as a string.
Each step goes through the digits from left to right and replaces every run of equal digits next to each other with the length of the run followed by the digit. The length is written in full, so a run of ten 1s becomes 101.
look_and_say("1", 1) # returns '11' look_and_say("1", 5) # returns '312211' look_and_say("3322251", 1) # returns '23321511'
In the last example the runs are 33, 222, 5 and 1, read as "two 3s, three 2s, one 5, one 1".
seed is a string of 1 to 10 digits0 <= steps <= 40, and with 0 steps the seed comes back unchangedFirst solves only, ranked by stars and then time.