11
Given is any integer x > 0 and any base y > 3.
- Sum all digits of x (if written in the set base).
- Multiply this by the highest possible digit (is always
base -1
). - Repeat until this value is
(y - 1) ^ 2
Searched is the count of iterations and the steps.
Example 1:
x= 739
y= 7
searched: (7 - 1) ^ 2 = 36
based: (b7)2104
sum: (dec)7
mul: (dec)42
based: (b7)60
sum: (dec)6
mul: (dec)36
2 steps needed -> answer is [2, 739, 42, 36] or [739, 42, 36, 2]
Example 2:
x = 1712
y = 19
s: 324
step1: 1712 -> 360
step2: 360 -> 648
step3: 648 -> 324
3 steps needed -> answer is [3, 1712, 360, 648, 324] or [1712, 360, 648, 324, 3]
Special:
In some cases (some combinations with a base of 3) you will not be able to get to (y - 1) ^ 2
like for x = 53
and y = 3
. For this reason y
needs to be bigger than 3 and you can ignore this.
The count of iterations need to be the first or the last value
This is code-golf lowest byte-count wins.
Requiring the number of steps in the answer seems like an unnecessary addition to the problem. My solution had to add 21 bytes to do what amounted to finding the length of a list and subtracting 1.
– ngenisis – 2016-12-11T22:32:56.653@ngenisis going with just an order of the output, but ignoring the method (array, stack, delim. string, multiple strings....). To keep track of 2 different things (final value and count) avoids the "blind" collecting of values (more or less) and is a good addition to my eye. Maybe a different approach will need 5 more bytes at the calculation but saves 8 at the counting part (just random numbers here). – Dirk Reichel – 2016-12-11T23:32:54.180