Monday Mini-Golf #4: JARVIS (Just Another Rather Vast set of Integer Sequences)

Pyth, 15 14 bytes

.uu|*GHhGjNT1Q

1 byte thanks to Dennis

Test Suite

This challenge feels like it was made for Pyth's reduce functions. One reduce over the digits, one reduce until the value stops changing, and we're good.


PowerShell, 92 91 90 88 87 bytes

($n=$args);while($n-gt9){$x=1;[char[]]"$n"|%{$x=if($y=$_-48){$x*$y}else{$x+1}};($n=$x)}

CJam, 26 25 24 22 bytes

riA,{_pAb{_2$*@)?}*j}j

or

ri{_pAb{_2$*@)?}*_9>}g

Try it online.

How it works

Both program essentially do the same; the first is a recursive approach, the second an iterative one. I'll explain the first, which I consider more interesting.

ri                     Read an integer from STDIN and push it on the stack.
  A,{               }j Initialize a memoized, recursive function j with the array
                       [0 ... 9] as "base cases". If j is called on an integer
                       below 10, it returns the element at that index of the base
                       cases (which is same integer) and does not execute the code
                       block. The base case array is filled with new values as j is
                       called again and again, but we do not use this feature.
     _p                Copy and print the integer on the stack.
       Ab              Convert it into its base-10 digits.
         {       }*    Fold; push the first digit, for each remaining digit:
          _2$*         Multiply copies of the accumulator and the current digit.
              @)       Increment the original accumulator.
                ?      Select the product if the digit is non-zero, else the sum.
                   j   Call j on the result.
                       If the result was less than 10, it is retrieved from the
                       base cases and pushed on the stack. CJam prints it before
                       exiting the program.