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
Problem Comments
4 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers16
Suggested Problems
-
16148 Solvers
-
Make a run-length companion vector
656 Solvers
-
Generate a vector like 1,2,2,3,3,3,4,4,4,4
13590 Solvers
-
The Answer to Life, the Universe, and Everything
574 Solvers
-
Converting numbers back from extended form
126 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!
Chris, we agree on everything except cases 11, 13 and 14. In those, I get a value of n that is smaller by 1.
I think the problem is in line 20 of your code. Notice that we agree except for the cases with period 1. I checked that our codes produce the same terms for cases 1 and 11.
Thanks Chris. You wrote very clearly that n was to be the 'start' of the periodic behavior, counting the initial seed as n=1, but somehow I took it to be something else. That's an interesting discovery about the final term. I tried 100,000 random seeds up to 12-digits and didn't find anything other than the two final values you mention.
I thought about possible final values because there's a constraint on the digits of terms after the initial seed. I haven't been able to think up another possible final state. Are there only two final states?