Problem 1084. Square Digits Number Chain Terminal Value (Inspired by Project Euler Problem 92)
Given a number n, return the terminal value of the number chain formed by summing the square of the digits. According to the Project Euler problem, this number chain always terminates with either 1 or 89.
Project Euler Problem 92: Link
Solution Stats
Problem Comments
-
3 Comments
Let consider the case x=954
954 -> 122 -> 9 -> 81 -> 65 -> 61 -> 37 -> 58 -> 89 -> 145 -> 42 -> 20 -> 4 -> 16 -> 37
So 37 is seen twice, it should end up with 37, no ?
No, 89 shows up before 37 does
By the description at ProjectEuler.net, it seems M is correct in their statement. The description there reads: "continuously [...] form a new number until it [that number just formed] has been seen before." That is exactly what M has done. Project Euler says furthermore: "[...] EVERY starting number will eventually arrive at 1 or 89." That is _not_ the same as stating: "this number chain always terminates with either 1 or 89". The key difference is in "arrives at" (the number appears) versus "terminates with" (the number is the first to appear twice in the sequence). In M's example, the sequence truly 'terminates with' 37 (as M said), but before it terminates the sequence had 'arrived at' 89.
Solution Comments
Show commentsProblem Recent Solvers235
Suggested Problems
-
It dseon't mettar waht oedrr the lrettes in a wrod are.
1966 Solvers
-
Program an exclusive OR operation with logical operators
729 Solvers
-
Find a subset that divides the vector into equal halves
391 Solvers
-
Check if number exists in vector
12753 Solvers
-
1438 Solvers
More from this Author56
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!