Cody Problems 40, 55, and 594 deal with the "look and say" sequence, in which each term describes the term before it. For example, the first few terms of sequence A001151 in the Online Encyclopedia of Integer Sequences are
8, 18, 1118, 3118, 132118, 1113122118
The second term is "one 8". The third is "one 1, one 8". The fourth is "three 1's, one 1". Et cetera. That is, each term is constructed by naming the runs of digits in the previous term.
In the sequence that I will call the "digit inventory sequence", each term is constructed as an inventory of the digits. If the first term is 8, then the first six terms are
8, 18, 1118, 3118, 211318, 31121318
The first four terms match those in the look-and-say, but the next terms differ. For example, because the fourth term has two 1's, one 3, and one 8, the fifth term is 211318.
Write a function that takes the first term of a digit inventory sequence and finds the nth term. Output the term as a character string.
Solution Stats
Problem Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers20
Suggested Problems
-
293 Solvers
-
Convert Roman to Arabic Numerals
120 Solvers
-
Find the maximum number of decimal places in a set of numbers
3369 Solvers
-
Magic is simple (for beginners)
11108 Solvers
-
Given a square and a circle, please decide whether the square covers more area.
1710 Solvers
More from this Author321
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!