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] integer a0

the A0 number

  • [output] an integer

the length of the repeat sequence

Puzzles

Stats:

CreatedFeb 15, 2017
PublishedFeb 15, 2017
Warriors Trained1660
Total Skips44
Total Code Submissions1597
Total Times Completed602
JavaScript Completions214
Python Completions349
Prolog Completions4
Haskell Completions14
C++ Completions58
C Completions16
Total Stars16
% of votes with a positive feedback rating91% of 148
Total "Very Satisfied" Votes128
Total "Somewhat Satisfied" Votes12
Total "Not Satisfied" Votes8
Total Rank Assessments11
Average Assessed Rank
7 kyu
Highest Assessed Rank
7 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • suic Avatar
  • smile67 Avatar
  • JohanWiltink Avatar
  • rowcased Avatar
  • stellartux Avatar
  • trashy_incel Avatar
  • o2001 Avatar
  • saudiGuy Avatar
Ad