Multiplicative persistence
TI-BASIC (TI-84), 30 32 31 bytes
-1 byte thanks to @SolomonUcko!
While Ans>9:Disp Ans:prod(int(10fPart(Ans10^(seq(-X-1,X,0,log(Ans:End:Ans
Input is in Ans
.
Output is displayed as the challenge requests. The trailing Ans
is needed to print the last step.
I will admit, I did not think of this formula myself, rather I found it here and modified it to better fit the challenge.
EDIT: Upon rereading the challenge, I realized that the program must terminate if the product is one digit. Hence, 2 bytes were to be added to account for this.
Example:
24456756
24456756
prgmCDGF8
24456756
201600
0
11112
11112
prgmCDGF8
11112
2
Explanation:
While Ans>9 ;loop until the product is one digit
Disp Ans ;display the current product
prod( ;get the product of...
int( ; the integer part of...
10fPart( ; ten times the fractional part of...
Ans ; each element in the following list times the
; current product
10^( ; multiplied by the list generated by using each
; element of the following list as an exponent
; for 10^n
seq(-X-1),X,0,log(Ans ; generate a list of exponents from -1 to -L where
; L = the length of the current product
End
Ans ;leave the final product in "Ans" and implicitly
; print it
Visual Model:
Ans
starts off as 125673
.
This model only covers the logic behind multiplying the digits; everything else is easier to understand.
seq(-X-1,X,0,log(Ans => seq(-X-1,X,0,5.0992
{-1 -2 -3 -4 -5 -6}
10^(...
{.1 .01 .001 1E-4 1E-5 1E-6}
Ans...
{12567.3 1256.73 125.673 12.5673 1.25673 .125673}
fPart(...
{.3 .73 .673 .5673 .25673 .125673}
10...
{3 7.3 6.73 5.673 2.5673 1.25673}
int(...
{3 7 6 5 2 1}
(the digits of the number, reversed)
prod(...
1260
(process is repeated again)
seq(-X-1,X,0,log(Ans => seq(-X-1,X,0,3.1004
{-1 -2 -3 -4}
10^(...
{.1 .01 .001 1E-4}
Ans...
{126 12.6 1.26 .126}
fPart(...
{0 .6 .26 .126}
10...
{0 6 2.6 1.26}
int(...
{0 6 2 1}
prod(...
0
(product is less than 10. loop ends)
Notes:
TI-BASIC is a tokenized language. Character count does not equal byte count.
10^(
is this one-byte token.
This program will not provide the correct sequence of products with integers greater than 14 digits long due to the limitations of decimal precision on the TI calculators.
K (ngn/k), 9 bytes
{*/.'$x}\
Try it online!
{
}\
keep applying the function in curly braces until the sequence converges
$x
format the argument as a string (list of characters)
.'
evaluate each (other dialects of k require a colon, .:'
)
*/
times over, i.e. product
05AB1E, 7 4 bytes
Δ=SP
Try it online or verify all test cases.
Explanation:
Δ # Loop until the number no longer changes:
= # Print the number with trailing newline (without popping the number itself)
# (which will be the implicit input in the first iteration)
SP # Convert the number to a list of digits, and calculate its product