Monday Mini-Golf: A series of short code-golf questions, posted (hopefully!) every Monday.
(Sorry I'm late again; I was away from my computer basically all of yesterday and today.)
Us programmers (especially the code-golfers) sure love arbitrary integer sequences. We even have an entire site dedicated to these sequences that currently has around 200,000 entries. In this challenge, we'll be implementing yet another set of these sequences.
Challenge
Your challenge is to write a program or function that takes in an integer N, and outputs a sequence of base 10 integers, where each next integer is determined in this way:
- Start at 1.
For each digit D in the previous integer's base 10 representation:
- If D is 0, add one to the current integer.
- Otherwise, multiply the current integer by D.
Details
- You may assume that 0 < N < 231.
- You must output each integer in the sequence, starting with the input number, until a number less than 10 is reached.
- The output may be an array, or a string separated by spaces, commas, newlines, or a combination of these.
- A trailing space and/or newline is allowed, but not a trailing comma.
- There should never be any leading zeroes.
Examples
Example 1: 77
This example is fairly straightforward:
77 = 1*7*7 = 49
49 = 1*4*9 = 36
36 = 1*3*6 = 18
18 = 1*1*8 = 8
Thus, the proper output is 77 49 36 18 8
.
Example 2: 90
Here we have:
90 = 1*9+1 = 10
10 = 1*1+1 = 2
So the output would be 90 10 2
.
Example 3: 806
Read the equations left-to-right:
806 = 1*8+1*6 = 54 (((1*8)+1)*6)
54 = 1*5*4 = 20
20 = 1*2+1 = 3
Output should be 806 54 20 3
.
Test-cases
The first number in each line is the input, and the full line is the expected output.
77 49 36 18 8
90 10 2
249 72 14 4
806 54 20 3
1337 63 18 8
9999 6561 180 9
10000 5
8675309 45369 3240 25 10 2
9999999 4782969 217728 1568 240 9
1234567890 362881 2304 28 16 6
As a reference, here's the proper next integers from 10 to 100:
Current | Next
--------+-----
10 | 2
11 | 1
12 | 2
13 | 3
14 | 4
15 | 5
16 | 6
17 | 7
18 | 8
19 | 9
20 | 3
21 | 2
22 | 4
23 | 6
24 | 8
25 | 10
26 | 12
27 | 14
28 | 16
29 | 18
30 | 4
31 | 3
32 | 6
33 | 9
34 | 12
35 | 15
36 | 18
37 | 21
38 | 24
39 | 27
40 | 5
41 | 4
42 | 8
43 | 12
44 | 16
45 | 20
46 | 24
47 | 28
48 | 32
49 | 36
50 | 6
51 | 5
52 | 10
53 | 15
54 | 20
55 | 25
56 | 30
57 | 35
58 | 40
59 | 45
60 | 7
61 | 6
62 | 12
63 | 18
64 | 24
65 | 30
66 | 36
67 | 42
68 | 48
69 | 54
70 | 8
71 | 7
72 | 14
73 | 21
74 | 28
75 | 35
76 | 42
77 | 49
78 | 56
79 | 63
80 | 9
81 | 8
82 | 16
83 | 24
84 | 32
85 | 40
86 | 48
87 | 56
88 | 64
89 | 72
90 | 10
91 | 9
92 | 18
93 | 27
94 | 36
95 | 45
96 | 54
97 | 63
98 | 72
99 | 81
100 | 3
You can find this list expanded to 10000 here.
Scoring
This is code-golf, so shortest valid code in bytes wins. Tiebreaker goes to submission that reached its final byte count first. The winner will be chosen next Monday, Oct 19. Good luck!
Edit: Congrats to your winner, @isaacg, using Pyth yet again for 14 bytes!