Let's construct a sequence
as follows:
is a given natural number, and
is the product of the digits of
. The persistence of
is defined as the smallest index n such that
.
Complete the function persistance(u0) which, for a given
, returns its persistence.
Solution Stats
Problem Comments
3 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers23
Suggested Problems
-
Extract leading non-zero digit
2257 Solvers
-
Sum the entries of each column of a matrix which satisfy a logical condition.
176 Solvers
-
Find the index of the largest value in any vector X=[4,3,4,5,9,12,0,4.....5]
405 Solvers
-
308 Solvers
-
8295 Solvers
More from this Author53
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Test cases 4,8,9 and 10 have some incorrect values.
I don't understand where the error is.
For example, for test 4, we have the sequence $u_0 = 97$, $u_1 = 9 \times 7 = 63$, $u_2 = 6 \times 3 = 18$, $u_3 = 1 \times 8 = 8$, so $n = 3$. So, the sequence for test case 4 is 97→63→18→8 and n=3 since it took 3 steps to reach a single-digit number from 97.
Similarly, for test 8 (with a randomly chosen number from the given list): $u_0$ in L and $u_1<10$ (the elements of L are chosen so that the product of the digits always gives a number < 10).
Sorry, that was my error! I had written my code to do addition rather than multiplication, and in many, but not all, cases that gave the same result for the persistence.