7 kyu
Simple Fun #129: Repeat Sequence Length
349 of 602myjinxin2015
Description:
Task
let F(N)
be the sum square of digits of N
. So:
F(1) = 1, F(3) = 9, F(123) = 14
Choose a number A
, the sequence { A0, A1, .. }
is defined as follows:
A0 = A
A1 = F(A0)
A2 = F(A1) ...
if A = 123
, we have:
123 → 14 (1 x 1 + 2 x 2 + 3 x 3)
→ 17 (1 x 1 + 4 x 4)
→ 50 (1 x 1 + 7 x 7)
→ 25 (5 x 5 + 0 x 0)
→ 29 (2 x 2 + 5 x 5)
→ 85 (2 x 2 + 9 x 9)
→ 89 (8 x 8 + 5 x 5) ---
→ 145 (8 x 8 + 9 x 9) |r
→ 42 (1 x 1 + 4 x 4 + 5 x 5) |e
→ 20 (4 x 4 + 2 x 2) |p
→ 4 (2 x 2 + 0 x 0) |e
→ 16 (4 x 4) |a
→ 37 (1 x 1 + 6 x 6) |t
→ 58 (3 x 3 + 7 x 7) |
→ 89 (5 x 5 + 8 x 8) ---
→ ......
As you can see, the sequence repeats itself. Interestingly, whatever A
is, there's an index such that from it, the sequence repeats again and again.
Let G(A)
be the minimum length of the repeat sequence with A0 = A
.
So G(123) = 8
(8 number : 89,145,42,20,4,16,37,58
)
Your task is to find G(A)
and return it.
Input/Output
[input]
integera0
the A0
number
[output]
an integer
the length of the repeat sequence
Puzzles
Similar Kata:
Stats:
Created | Feb 15, 2017 |
Published | Feb 15, 2017 |
Warriors Trained | 1660 |
Total Skips | 44 |
Total Code Submissions | 1597 |
Total Times Completed | 602 |
JavaScript Completions | 214 |
Python Completions | 349 |
Prolog Completions | 4 |
Haskell Completions | 14 |
C++ Completions | 58 |
C Completions | 16 |
Total Stars | 16 |
% of votes with a positive feedback rating | 91% of 148 |
Total "Very Satisfied" Votes | 128 |
Total "Somewhat Satisfied" Votes | 12 |
Total "Not Satisfied" Votes | 8 |
Total Rank Assessments | 11 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 7 kyu |
Lowest Assessed Rank | 7 kyu |