Problem 2040. Additive persistence
Inspired by Problem 2008 created by Ziko.
In mathematics, the persistence of a number is the number of times one must apply a given operation to an integer before reaching a fixed point; where further application does not change the number any more (Wikipedia).
Problem 2008 is an example of multiplicative persistence. Can you code an additive persistence ?
2718->2+7+1+8=18->1+8=9. So the persistence of 2718 is 2.
You can use the tips : num2str(666)-'0'=[6 6 6].
Solution Stats
Problem Comments
-
1 Comment
Tip was so instructive... Thanks
Solution Comments
Show commentsProblem Recent Solvers172
Suggested Problems
-
Find state names that end with the letter A
1186 Solvers
-
335 Solvers
-
Back to basics 19 - character types
265 Solvers
-
We love vectorized solutions. Problem 1 : remove the row average.
832 Solvers
-
1476 Solvers
More from this Author43
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!