Problem 51246. Characterize the final state of another digit inventory sequence

Cody Problems 46122 and 46571 involved a digit inventory sequence in which one term in the sequence describes the previous. For example, if one term is 411, the next would be 2114: two 1’s, one 4. For some starting numbers, the sequence reaches a steady state, but for others, the terms oscillate.
A different form of a digit inventory is formed by listing the counts of all digits—in the order 1-9 and 0—and concatenating them for the next term in the sequence. If the initial seed is 570, then the next three terms would be
0000101001, 3000000007, 0010001008
The first term arises because 570 has zero 1s, 2s, 3s, and 4s; one 5; zero 6s, one 7; zero 8s and 9s; and one 0. The second term arises because the first has three 1s, seven 0s, and zero of everything else. If we continue to generate terms, we will find that the seventh and eighth terms will repeat.
At first, I thought that this sequence always reaches a state in which these same two terms oscillate, but I have since found a few seeds that lead to a steady state.
Write a function that takes a seed as a string and determines the number of the term at which the final state begins and the period of the repeated terms. Take the initial seed to be term 1.
Optional: The function is not required to return the terms themselves, but the terms in the final state are interesting. The seeds in the test suite lead to only two sets of final terms. Can you find seeds that lead to different final terms?

Solution Stats

50.0% Correct | 50.0% Incorrect
Last Solution submitted on Mar 22, 2024

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers14

Suggested Problems

More from this Author265

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!