Multiplicative persistence
Multi tool use
$begingroup$
Multiplicative Persistence
- Multiply all the digits in a number
- Repeat until you have a single digit left
As explained by Numberphile:
Numberphile "What's special about 277777788888899?"
Numberphile "Multiplicative Persistence (extra footage)"
Example
- 277777788888899 → 2x7x7x7x7x7x7x8x8x8x8x8x8x9x9 = 4996238671872
- 4996238671872 → 4x9x9x6x2x3x8x6x7x1x8x7x2 = 438939648
- 438939648 → 4x3x8x9x3x9x6x4x8 = 4478976
- 4478976 → 4x4x7x8x9x7x6 = 338688
- 338688 → 3x3x8x6x8x8 = 27648
- 27648 → 2x7x6x4x8 = 2688
- 2688 → 2x6x8x8 = 768
- 768 → 7x6x8 = 336
- 336 → 3x3x6 = 54
- 54 → 5x4 = 20
- 20 → 2x0 = 0
This is the current record, by the way: the smallest number with the largest number of steps.
Golf
A program that takes any whole number as input and then outputs the result of each step, starting with the input itself, until we hit a single digit. For 277777788888899 the output should be
277777788888899
4996238671872
438939648
4478976
338688
27648
2688
768
336
54
20
0
(Counting the number of steps is left as an exercise to the user).
More Examples
From A003001:
25
10
0
From A003001 as well:
68889
27648
2688
768
336
54
20
0
From the Numberphile video:
327
42
8
So there has been a question about Additive Persistence, but this is Multiplicative Persistence. Also, that question asks for the number of steps as output, while I'm interested in seeing the intermediate results.
code-golf math arithmetic repeated-transformation
$endgroup$
|
show 3 more comments
$begingroup$
Multiplicative Persistence
- Multiply all the digits in a number
- Repeat until you have a single digit left
As explained by Numberphile:
Numberphile "What's special about 277777788888899?"
Numberphile "Multiplicative Persistence (extra footage)"
Example
- 277777788888899 → 2x7x7x7x7x7x7x8x8x8x8x8x8x9x9 = 4996238671872
- 4996238671872 → 4x9x9x6x2x3x8x6x7x1x8x7x2 = 438939648
- 438939648 → 4x3x8x9x3x9x6x4x8 = 4478976
- 4478976 → 4x4x7x8x9x7x6 = 338688
- 338688 → 3x3x8x6x8x8 = 27648
- 27648 → 2x7x6x4x8 = 2688
- 2688 → 2x6x8x8 = 768
- 768 → 7x6x8 = 336
- 336 → 3x3x6 = 54
- 54 → 5x4 = 20
- 20 → 2x0 = 0
This is the current record, by the way: the smallest number with the largest number of steps.
Golf
A program that takes any whole number as input and then outputs the result of each step, starting with the input itself, until we hit a single digit. For 277777788888899 the output should be
277777788888899
4996238671872
438939648
4478976
338688
27648
2688
768
336
54
20
0
(Counting the number of steps is left as an exercise to the user).
More Examples
From A003001:
25
10
0
From A003001 as well:
68889
27648
2688
768
336
54
20
0
From the Numberphile video:
327
42
8
So there has been a question about Additive Persistence, but this is Multiplicative Persistence. Also, that question asks for the number of steps as output, while I'm interested in seeing the intermediate results.
code-golf math arithmetic repeated-transformation
$endgroup$
$begingroup$
Bonus: find a new record: smallest number with the largest number of steps. Caveat: conjecture has it that 11 is the largest possible.
$endgroup$
– SQB
Mar 21 at 14:31
7
$begingroup$
You probably should include a few more tests cases that do not end with $0$.
$endgroup$
– Arnauld
Mar 21 at 14:33
$begingroup$
Came to make this post, found it already existing, gg
$endgroup$
– cat
Mar 21 at 14:55
$begingroup$
is a single digit valid input?
$endgroup$
– dzaima
Mar 21 at 18:30
1
$begingroup$
In the Numberphile video, Matt Parker states that searches have been done to several hundred digits.
$endgroup$
– HardScale
Mar 21 at 21:46
|
show 3 more comments
$begingroup$
Multiplicative Persistence
- Multiply all the digits in a number
- Repeat until you have a single digit left
As explained by Numberphile:
Numberphile "What's special about 277777788888899?"
Numberphile "Multiplicative Persistence (extra footage)"
Example
- 277777788888899 → 2x7x7x7x7x7x7x8x8x8x8x8x8x9x9 = 4996238671872
- 4996238671872 → 4x9x9x6x2x3x8x6x7x1x8x7x2 = 438939648
- 438939648 → 4x3x8x9x3x9x6x4x8 = 4478976
- 4478976 → 4x4x7x8x9x7x6 = 338688
- 338688 → 3x3x8x6x8x8 = 27648
- 27648 → 2x7x6x4x8 = 2688
- 2688 → 2x6x8x8 = 768
- 768 → 7x6x8 = 336
- 336 → 3x3x6 = 54
- 54 → 5x4 = 20
- 20 → 2x0 = 0
This is the current record, by the way: the smallest number with the largest number of steps.
Golf
A program that takes any whole number as input and then outputs the result of each step, starting with the input itself, until we hit a single digit. For 277777788888899 the output should be
277777788888899
4996238671872
438939648
4478976
338688
27648
2688
768
336
54
20
0
(Counting the number of steps is left as an exercise to the user).
More Examples
From A003001:
25
10
0
From A003001 as well:
68889
27648
2688
768
336
54
20
0
From the Numberphile video:
327
42
8
So there has been a question about Additive Persistence, but this is Multiplicative Persistence. Also, that question asks for the number of steps as output, while I'm interested in seeing the intermediate results.
code-golf math arithmetic repeated-transformation
$endgroup$
Multiplicative Persistence
- Multiply all the digits in a number
- Repeat until you have a single digit left
As explained by Numberphile:
Numberphile "What's special about 277777788888899?"
Numberphile "Multiplicative Persistence (extra footage)"
Example
- 277777788888899 → 2x7x7x7x7x7x7x8x8x8x8x8x8x9x9 = 4996238671872
- 4996238671872 → 4x9x9x6x2x3x8x6x7x1x8x7x2 = 438939648
- 438939648 → 4x3x8x9x3x9x6x4x8 = 4478976
- 4478976 → 4x4x7x8x9x7x6 = 338688
- 338688 → 3x3x8x6x8x8 = 27648
- 27648 → 2x7x6x4x8 = 2688
- 2688 → 2x6x8x8 = 768
- 768 → 7x6x8 = 336
- 336 → 3x3x6 = 54
- 54 → 5x4 = 20
- 20 → 2x0 = 0
This is the current record, by the way: the smallest number with the largest number of steps.
Golf
A program that takes any whole number as input and then outputs the result of each step, starting with the input itself, until we hit a single digit. For 277777788888899 the output should be
277777788888899
4996238671872
438939648
4478976
338688
27648
2688
768
336
54
20
0
(Counting the number of steps is left as an exercise to the user).
More Examples
From A003001:
25
10
0
From A003001 as well:
68889
27648
2688
768
336
54
20
0
From the Numberphile video:
327
42
8
So there has been a question about Additive Persistence, but this is Multiplicative Persistence. Also, that question asks for the number of steps as output, while I'm interested in seeing the intermediate results.
code-golf math arithmetic repeated-transformation
code-golf math arithmetic repeated-transformation
edited 2 days ago
SQB
asked Mar 21 at 14:20
SQBSQB
479314
479314
$begingroup$
Bonus: find a new record: smallest number with the largest number of steps. Caveat: conjecture has it that 11 is the largest possible.
$endgroup$
– SQB
Mar 21 at 14:31
7
$begingroup$
You probably should include a few more tests cases that do not end with $0$.
$endgroup$
– Arnauld
Mar 21 at 14:33
$begingroup$
Came to make this post, found it already existing, gg
$endgroup$
– cat
Mar 21 at 14:55
$begingroup$
is a single digit valid input?
$endgroup$
– dzaima
Mar 21 at 18:30
1
$begingroup$
In the Numberphile video, Matt Parker states that searches have been done to several hundred digits.
$endgroup$
– HardScale
Mar 21 at 21:46
|
show 3 more comments
$begingroup$
Bonus: find a new record: smallest number with the largest number of steps. Caveat: conjecture has it that 11 is the largest possible.
$endgroup$
– SQB
Mar 21 at 14:31
7
$begingroup$
You probably should include a few more tests cases that do not end with $0$.
$endgroup$
– Arnauld
Mar 21 at 14:33
$begingroup$
Came to make this post, found it already existing, gg
$endgroup$
– cat
Mar 21 at 14:55
$begingroup$
is a single digit valid input?
$endgroup$
– dzaima
Mar 21 at 18:30
1
$begingroup$
In the Numberphile video, Matt Parker states that searches have been done to several hundred digits.
$endgroup$
– HardScale
Mar 21 at 21:46
$begingroup$
Bonus: find a new record: smallest number with the largest number of steps. Caveat: conjecture has it that 11 is the largest possible.
$endgroup$
– SQB
Mar 21 at 14:31
$begingroup$
Bonus: find a new record: smallest number with the largest number of steps. Caveat: conjecture has it that 11 is the largest possible.
$endgroup$
– SQB
Mar 21 at 14:31
7
7
$begingroup$
You probably should include a few more tests cases that do not end with $0$.
$endgroup$
– Arnauld
Mar 21 at 14:33
$begingroup$
You probably should include a few more tests cases that do not end with $0$.
$endgroup$
– Arnauld
Mar 21 at 14:33
$begingroup$
Came to make this post, found it already existing, gg
$endgroup$
– cat
Mar 21 at 14:55
$begingroup$
Came to make this post, found it already existing, gg
$endgroup$
– cat
Mar 21 at 14:55
$begingroup$
is a single digit valid input?
$endgroup$
– dzaima
Mar 21 at 18:30
$begingroup$
is a single digit valid input?
$endgroup$
– dzaima
Mar 21 at 18:30
1
1
$begingroup$
In the Numberphile video, Matt Parker states that searches have been done to several hundred digits.
$endgroup$
– HardScale
Mar 21 at 21:46
$begingroup$
In the Numberphile video, Matt Parker states that searches have been done to several hundred digits.
$endgroup$
– HardScale
Mar 21 at 21:46
|
show 3 more comments
44 Answers
44
active
oldest
votes
1 2
next
$begingroup$
TI-BASIC (TI-84), 30 32 bytes
While Ans>9:Disp Ans:prod(int(10fPart(Ansseq(10^(-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:Disp Ans:prod(int(10fPart(Ansseq(10^(-X-1),X,0,log(Ans:End:Ans ;full program
While Ans>9 End ;loop until the product is one digit
Disp Ans ;print the current number
prod( ;get the product of
seq( ;the list generated by
10^(-X-1), ;consecutive powers of ten
X, ;using X as the increment variable
0, ;starting at 0
log(Ans ;ending at the length of the current number
;(implicit increment by 1)
Ans ;multiplied by the current number
fPart( ;then taking the fractional part of each element
10 ;multiplied by 10
int( ;then truncating each element
Ans ;output last step since it was skipped
Visual Model:Ans
starts off as 125673
.
This model only covers the logic behind multiplying the digits; everything else is easier to understand.
seq(10^(-X-1),X,0,log(Ans => seq(10^(-X-1),X,0,5.0992
{.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(10^(-X-1),X,0,log(Ans => seq(10^(-X-1),X,0,3.1004
{.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.
$endgroup$
add a comment |
$begingroup$
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
$endgroup$
add a comment |
$begingroup$
dzaima/APL, 14 11 bytes
∪{×/⍎¨⍕⍵}⍡≡
Try it online!
$endgroup$
add a comment |
$begingroup$
R, 59 bytes
n=scan();while(print(n)>9)n=prod(n%/%10^(nchar(n):1-1)%%10)
Try it online!
Since print
invisibly
returns its input, we can use print(n)
inside the while
loop to simulate a do-while
loop. This is inspired by one of my tips for golfing in R.
The header helps prevent large numbers from being printed in scientific notation.
$endgroup$
add a comment |
$begingroup$
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
$endgroup$
add a comment |
$begingroup$
Perl 6, 23 bytes
{$_,{[*] .comb}…10>*}
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 2, 46 43 bytes
-3 thanks to xnor (chained comparison)
def f(n):print n;n>9>f(eval('*'.join(`n`)))
Try it online!
$endgroup$
$begingroup$
You can do>
in place ofand
.
$endgroup$
– xnor
2 days ago
$begingroup$
@xnor thanks, easy to forget that will work.
$endgroup$
– Jonathan Allan
2 days ago
add a comment |
$begingroup$
Wolfram Language (Mathematica), 47 bytes
Most@FixedPointList[Times@@IntegerDigits@#&,#]&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 45 bytes
#//.x_/;x>9:>Times@@IntegerDigits@x&&Print@x&
Try it online!
$endgroup$
add a comment |
$begingroup$
Jelly, 4 bytes
DP$Ƭ
Try it online!
Explanation
D | convert to decimal digits
P | take the product
$ | previous two links as a monad
Ƭ | loop until no change, collecting all intermediate results
As a bonus, here's a TIO which will find the numbers with the largest number of steps for a given range of numbers of digits. It scales well even on TIO.
$endgroup$
add a comment |
$begingroup$
Julia 0.7, 36 bytes
f(n)=n>9?[n,f(prod(digits(n)))...]:n
Try it online!
$endgroup$
add a comment |
$begingroup$
PowerShell, 54 bytes
for($a=$args;$a-gt9){$a;$a=("$a"|% t*y)-join"*"|iex}$a
Try it online!
Iterative method that first writes the input argument, then converts it into a string and pipes it into a character array. This array is joined by a single asterisks, and executed as a command with the invoke expression alias. Since this writes Starting number down to the last number greater than 0, (20, in the given test scenario), I add a final $a
to the end to output.
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 79 74 68 bytes
void f(int a){Print(a);if(a>9)f((a+"").Aggregate(1,(j,k)=>k%48*j));}
I try to stay away from recursion in C# due to how long the method declaration is, but in this case it saves compared to a loop.
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 2, 61 62 59 bytes
def f(n):print n;n>9and f(reduce(int.__mul__,map(int,`n`)))
Try it online!
-3 bytes, thanks to Jonathan Allan
$endgroup$
$begingroup$
Doesn't work for inputs that don't end with a 0 on their last iteration, for example 23
$endgroup$
– Embodiment of Ignorance
Mar 21 at 15:40
$begingroup$
int.__mul__
is three bytes less thanlambda a,b:a*b
$endgroup$
– Jonathan Allan
Mar 21 at 17:17
$begingroup$
@JonathanAllan Thanks! I knew there had to be something like that
$endgroup$
– TFeld
Mar 21 at 19:05
$begingroup$
Changef(reduce(int.__mul__,map(int,`n`)))
tof(eval('*'.join(`n`)))
to save 13 bytes.
$endgroup$
– mypetlion
Mar 21 at 20:34
$begingroup$
@mypetlion ...I already did that in another post.
$endgroup$
– Jonathan Allan
Mar 21 at 20:52
add a comment |
$begingroup$
perl 5 (-n
-M5.01
), 32 30 25 bytes
say$_=eval;s/B/*/g&&redo
25 bytes
30 bytes
32 bytes
$endgroup$
$begingroup$
You should mention that this uses-lpF//
$endgroup$
– Grimy
2 days ago
1
$begingroup$
@Grimy i could save 2 bytes without using-lpF//
, updating
$endgroup$
– Nahuel Fouilleul
2 days ago
add a comment |
$begingroup$
MathGolf, 9 10 bytes
h(ôo▒ε*h(→
Try it online!
Now it correctly handles inputs that are single digits. Not perfect, but at least it is correct.
Explanation
h( check length of input number and decrease by 1
ö → while true with pop using the next 6 operators
p print with newline
▒ split to list of chars/digits
ε* reduce list by multiplication
h( length of TOS without popping, subtracted by 1 (exits when len(TOS) == 1)
$endgroup$
$begingroup$
The output for a single digit input should be one copy of the number - clarified in the comments
$endgroup$
– dzaima
Mar 21 at 18:38
$begingroup$
@dzaima I'll look into it, and update the answer when it's solved
$endgroup$
– maxb
2 days ago
add a comment |
$begingroup$
JavaScript (ES6), 45 bytes
Returns an array of integers.
f=n=>[n,...n>9?f(eval([...n+''].join`*`)):]
Try it online!
$endgroup$
add a comment |
$begingroup$
PowerShell, 51 bytes
filter f{$_
if($_-gt9){("$_"|% t*y)-join'*'|iex|f}}
Try it online!
$endgroup$
add a comment |
$begingroup$
Haskell, 45 bytes
f n=n:[x|n>9,x<-f$product$read.pure<$>show n]
Try it online!
$endgroup$
add a comment |
$begingroup$
PHP, 63 bytes
<?=$n=$argn;while($n>9)echo"
",$n=array_product(str_split($n));
Iterative version, call with php -nF
input from STDIN
.
Try it online!
PHP, 72 71 bytes
function h($n){echo"$n
",($n=array_product(str_split($n)))>9?h($n):$n;}
Try it online!
Recursive version, as function.
Input: 277777788888899
277777788888899
4996238671872
438939648
4478976
338688
27648
2688
768
336
54
20
0
Input: 23
23
6
$endgroup$
add a comment |
$begingroup$
J, 16 bytes
([:*/,.&.":)^:a:
Try it online!
$endgroup$
add a comment |
$begingroup$
Ruby, 38 35 34 bytes
f=->n{p(n)>9&&f[eval n.digits*?*]}
Try it online!
1 byte saved by by G B.
$endgroup$
add a comment |
$begingroup$
Brachylog, 7 bytes
ẉ?Ḋ|ẹ×↰
Try it online!
Explanation
ẉ Write the input followed by a linebreak
?Ḋ If the input is a single digit, then it's over
| Otherwise
ẹ Split the input into a list of digits
× Multiply them together
↰ Recursive call with the result of the multiplication as input
$endgroup$
$begingroup$
I gave it a try myself. Forgot about the Ḋ. The rest i had the same.
$endgroup$
– Kroppeb
Mar 21 at 19:33
add a comment |
$begingroup$
JavaScript (Babel Node), 46 bytes
f=a=>a>9?[a,...f(eval([...a+''].join`*`))]:[a]
Try it online!
JavaScript (Babel Node), 44 bytes
If the input can be taken as String
f=a=>a>9?[a,...f(''+eval([...a].join`*`))]:a
Try it online!
$endgroup$
$begingroup$
@Arnauld Yes, I just edited and added the wrong code. Im still looking for something using only strings instead arrays
$endgroup$
– Luis felipe De jesus Munoz
Mar 21 at 15:12
add a comment |
$begingroup$
PowerShell, 64 59 bytes
for($a="$args";9-lt$a){$a;$a="$(($a|% t*y)-join'*'|iex)"}$a
Try it online!
Iterative method. Takes input and stores it into $a
, then enters a for
loop so long as the length of $a
is two or more (i.e., it's bigger than 9
). Inside the loop we output $a
and then recalculate it by converting it t
oCharArray
, join
ing it together with *
, and then iex
(short for Invoke-Expression
and similar to eval
). Once we're out of the loop, we have a single digit left to print, so we place $a
onto the pipeline again.
-5 bytes thanks to KGlasier.
$endgroup$
$begingroup$
You could use the comparison9-lt$a
instead of$a.length-1
to save 5 bytes. And if you didn't go string based the whole time you could cut off a decent chunk. Check out my powershell attempt if you want!
$endgroup$
– KGlasier
Mar 21 at 16:22
add a comment |
$begingroup$
APL(NARS), 19 chars, 38 bytes
{⍵≤9:⍵⋄∇×/⍎¨⍕⍵⊣⎕←⍵}
test:
f←{⍵≤9:⍵⋄∇×/⍎¨⍕⍵⊣⎕←⍵}
f 23
23
6
f 27648
27648
2688
768
336
54
20
0
$endgroup$
add a comment |
$begingroup$
Charcoal, 13 bytes
θW⊖Lθ«≔IΠθθ⸿θ
Try it online! Link is to verbose version of code. Explanation:
θ
Print the input for the first time.
W⊖Lθ«
Repeat while the length of the input is not 1.
≔IΠθθ
Replace the input with its digital product cast to string.
⸿θ
Print the input on a new line.
$endgroup$
add a comment |
$begingroup$
C (gcc), 58 bytes
f(n,t){for(;n=printf("%dn",t=n)>2;)for(;n*=t%10,t/=10;);}
Try it online!
Iterative approach turns out to be 1 byte shorter.
f(n,t){
for(;n=printf("%dn",t=n) //print and update current number
>2;) //until only one digit is printed
for(;n*=t%10,t/=10;); //n*= product of digits of t (step)
}
C (gcc), 61 59 bytes (recursive)
f(n){printf("%dn",n)>2&&f(p(n));}p(n){n=n?n%10*p(n/10):1;}
Try it online!
Recursion seems to be shorter than iteration for both print and step...
$endgroup$
add a comment |
$begingroup$
Retina, 24 bytes
.+~(`
.
$&$*
^
.+¶$$.(
Try it online! Explanation:
.+~(`
Print the current value on its own line at the start of every loop until it stops changing and don't print the unchanged value twice. Evaluate the current value at the end of each loop.
.
$&$*
Add a *
after each digit.
^
.+¶$$.(
Finish turning the input into an expression that evaluates to the digital product.
Just for the record, Retina can do this in one line (25 bytes):
.+"¶"<~[".+¶$.("|'*]'*L`.
$endgroup$
add a comment |
$begingroup$
Java, 112 bytes
"Lossy conversion" thanks Java for the extra ~15 bytes
Obligatory stream abuse recursion answer
long f(long n){System.out.println(n);return n<10?n:f((n+"").chars().mapToLong(i->i).reduce(1,(x,y)->x*(y-48)));}
Try it online
$endgroup$
$begingroup$
I'm pretty sure you only need to supportint
$endgroup$
– Embodiment of Ignorance
2 days ago
$begingroup$
@EmbodimentofIgnorance then it fails for277777788888899
since4996238671872
is too large for an int
$endgroup$
– Benjamin Urquhart
yesterday
add a comment |
1 2
next
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "200"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f181958%2fmultiplicative-persistence%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
44 Answers
44
active
oldest
votes
44 Answers
44
active
oldest
votes
active
oldest
votes
active
oldest
votes
1 2
next
$begingroup$
TI-BASIC (TI-84), 30 32 bytes
While Ans>9:Disp Ans:prod(int(10fPart(Ansseq(10^(-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:Disp Ans:prod(int(10fPart(Ansseq(10^(-X-1),X,0,log(Ans:End:Ans ;full program
While Ans>9 End ;loop until the product is one digit
Disp Ans ;print the current number
prod( ;get the product of
seq( ;the list generated by
10^(-X-1), ;consecutive powers of ten
X, ;using X as the increment variable
0, ;starting at 0
log(Ans ;ending at the length of the current number
;(implicit increment by 1)
Ans ;multiplied by the current number
fPart( ;then taking the fractional part of each element
10 ;multiplied by 10
int( ;then truncating each element
Ans ;output last step since it was skipped
Visual Model:Ans
starts off as 125673
.
This model only covers the logic behind multiplying the digits; everything else is easier to understand.
seq(10^(-X-1),X,0,log(Ans => seq(10^(-X-1),X,0,5.0992
{.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(10^(-X-1),X,0,log(Ans => seq(10^(-X-1),X,0,3.1004
{.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.
$endgroup$
add a comment |
$begingroup$
TI-BASIC (TI-84), 30 32 bytes
While Ans>9:Disp Ans:prod(int(10fPart(Ansseq(10^(-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:Disp Ans:prod(int(10fPart(Ansseq(10^(-X-1),X,0,log(Ans:End:Ans ;full program
While Ans>9 End ;loop until the product is one digit
Disp Ans ;print the current number
prod( ;get the product of
seq( ;the list generated by
10^(-X-1), ;consecutive powers of ten
X, ;using X as the increment variable
0, ;starting at 0
log(Ans ;ending at the length of the current number
;(implicit increment by 1)
Ans ;multiplied by the current number
fPart( ;then taking the fractional part of each element
10 ;multiplied by 10
int( ;then truncating each element
Ans ;output last step since it was skipped
Visual Model:Ans
starts off as 125673
.
This model only covers the logic behind multiplying the digits; everything else is easier to understand.
seq(10^(-X-1),X,0,log(Ans => seq(10^(-X-1),X,0,5.0992
{.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(10^(-X-1),X,0,log(Ans => seq(10^(-X-1),X,0,3.1004
{.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.
$endgroup$
add a comment |
$begingroup$
TI-BASIC (TI-84), 30 32 bytes
While Ans>9:Disp Ans:prod(int(10fPart(Ansseq(10^(-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:Disp Ans:prod(int(10fPart(Ansseq(10^(-X-1),X,0,log(Ans:End:Ans ;full program
While Ans>9 End ;loop until the product is one digit
Disp Ans ;print the current number
prod( ;get the product of
seq( ;the list generated by
10^(-X-1), ;consecutive powers of ten
X, ;using X as the increment variable
0, ;starting at 0
log(Ans ;ending at the length of the current number
;(implicit increment by 1)
Ans ;multiplied by the current number
fPart( ;then taking the fractional part of each element
10 ;multiplied by 10
int( ;then truncating each element
Ans ;output last step since it was skipped
Visual Model:Ans
starts off as 125673
.
This model only covers the logic behind multiplying the digits; everything else is easier to understand.
seq(10^(-X-1),X,0,log(Ans => seq(10^(-X-1),X,0,5.0992
{.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(10^(-X-1),X,0,log(Ans => seq(10^(-X-1),X,0,3.1004
{.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.
$endgroup$
TI-BASIC (TI-84), 30 32 bytes
While Ans>9:Disp Ans:prod(int(10fPart(Ansseq(10^(-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:Disp Ans:prod(int(10fPart(Ansseq(10^(-X-1),X,0,log(Ans:End:Ans ;full program
While Ans>9 End ;loop until the product is one digit
Disp Ans ;print the current number
prod( ;get the product of
seq( ;the list generated by
10^(-X-1), ;consecutive powers of ten
X, ;using X as the increment variable
0, ;starting at 0
log(Ans ;ending at the length of the current number
;(implicit increment by 1)
Ans ;multiplied by the current number
fPart( ;then taking the fractional part of each element
10 ;multiplied by 10
int( ;then truncating each element
Ans ;output last step since it was skipped
Visual Model:Ans
starts off as 125673
.
This model only covers the logic behind multiplying the digits; everything else is easier to understand.
seq(10^(-X-1),X,0,log(Ans => seq(10^(-X-1),X,0,5.0992
{.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(10^(-X-1),X,0,log(Ans => seq(10^(-X-1),X,0,3.1004
{.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.
edited 23 hours ago
answered Mar 21 at 16:22
TauTau
626211
626211
add a comment |
add a comment |
$begingroup$
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
$endgroup$
add a comment |
$begingroup$
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
$endgroup$
add a comment |
$begingroup$
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
$endgroup$
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
edited 2 days ago
answered Mar 21 at 15:18
ngnngn
7,29112560
7,29112560
add a comment |
add a comment |
$begingroup$
dzaima/APL, 14 11 bytes
∪{×/⍎¨⍕⍵}⍡≡
Try it online!
$endgroup$
add a comment |
$begingroup$
dzaima/APL, 14 11 bytes
∪{×/⍎¨⍕⍵}⍡≡
Try it online!
$endgroup$
add a comment |
$begingroup$
dzaima/APL, 14 11 bytes
∪{×/⍎¨⍕⍵}⍡≡
Try it online!
$endgroup$
dzaima/APL, 14 11 bytes
∪{×/⍎¨⍕⍵}⍡≡
Try it online!
edited Mar 21 at 19:10
answered Mar 21 at 14:37
dzaimadzaima
15.8k22059
15.8k22059
add a comment |
add a comment |
$begingroup$
R, 59 bytes
n=scan();while(print(n)>9)n=prod(n%/%10^(nchar(n):1-1)%%10)
Try it online!
Since print
invisibly
returns its input, we can use print(n)
inside the while
loop to simulate a do-while
loop. This is inspired by one of my tips for golfing in R.
The header helps prevent large numbers from being printed in scientific notation.
$endgroup$
add a comment |
$begingroup$
R, 59 bytes
n=scan();while(print(n)>9)n=prod(n%/%10^(nchar(n):1-1)%%10)
Try it online!
Since print
invisibly
returns its input, we can use print(n)
inside the while
loop to simulate a do-while
loop. This is inspired by one of my tips for golfing in R.
The header helps prevent large numbers from being printed in scientific notation.
$endgroup$
add a comment |
$begingroup$
R, 59 bytes
n=scan();while(print(n)>9)n=prod(n%/%10^(nchar(n):1-1)%%10)
Try it online!
Since print
invisibly
returns its input, we can use print(n)
inside the while
loop to simulate a do-while
loop. This is inspired by one of my tips for golfing in R.
The header helps prevent large numbers from being printed in scientific notation.
$endgroup$
R, 59 bytes
n=scan();while(print(n)>9)n=prod(n%/%10^(nchar(n):1-1)%%10)
Try it online!
Since print
invisibly
returns its input, we can use print(n)
inside the while
loop to simulate a do-while
loop. This is inspired by one of my tips for golfing in R.
The header helps prevent large numbers from being printed in scientific notation.
edited Mar 21 at 20:08
answered Mar 21 at 14:50
GiuseppeGiuseppe
17.1k31152
17.1k31152
add a comment |
add a comment |
$begingroup$
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
$endgroup$
add a comment |
$begingroup$
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
$endgroup$
add a comment |
$begingroup$
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
$endgroup$
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
edited 2 days ago
answered Mar 21 at 14:30
Kevin CruijssenKevin Cruijssen
41.3k567213
41.3k567213
add a comment |
add a comment |
$begingroup$
Perl 6, 23 bytes
{$_,{[*] .comb}…10>*}
Try it online!
$endgroup$
add a comment |
$begingroup$
Perl 6, 23 bytes
{$_,{[*] .comb}…10>*}
Try it online!
$endgroup$
add a comment |
$begingroup$
Perl 6, 23 bytes
{$_,{[*] .comb}…10>*}
Try it online!
$endgroup$
Perl 6, 23 bytes
{$_,{[*] .comb}…10>*}
Try it online!
answered Mar 21 at 15:50
GrimyGrimy
2,5711019
2,5711019
add a comment |
add a comment |
$begingroup$
Python 2, 46 43 bytes
-3 thanks to xnor (chained comparison)
def f(n):print n;n>9>f(eval('*'.join(`n`)))
Try it online!
$endgroup$
$begingroup$
You can do>
in place ofand
.
$endgroup$
– xnor
2 days ago
$begingroup$
@xnor thanks, easy to forget that will work.
$endgroup$
– Jonathan Allan
2 days ago
add a comment |
$begingroup$
Python 2, 46 43 bytes
-3 thanks to xnor (chained comparison)
def f(n):print n;n>9>f(eval('*'.join(`n`)))
Try it online!
$endgroup$
$begingroup$
You can do>
in place ofand
.
$endgroup$
– xnor
2 days ago
$begingroup$
@xnor thanks, easy to forget that will work.
$endgroup$
– Jonathan Allan
2 days ago
add a comment |
$begingroup$
Python 2, 46 43 bytes
-3 thanks to xnor (chained comparison)
def f(n):print n;n>9>f(eval('*'.join(`n`)))
Try it online!
$endgroup$
Python 2, 46 43 bytes
-3 thanks to xnor (chained comparison)
def f(n):print n;n>9>f(eval('*'.join(`n`)))
Try it online!
edited 2 days ago
answered Mar 21 at 17:33
Jonathan AllanJonathan Allan
53.4k535172
53.4k535172
$begingroup$
You can do>
in place ofand
.
$endgroup$
– xnor
2 days ago
$begingroup$
@xnor thanks, easy to forget that will work.
$endgroup$
– Jonathan Allan
2 days ago
add a comment |
$begingroup$
You can do>
in place ofand
.
$endgroup$
– xnor
2 days ago
$begingroup$
@xnor thanks, easy to forget that will work.
$endgroup$
– Jonathan Allan
2 days ago
$begingroup$
You can do
>
in place of and
.$endgroup$
– xnor
2 days ago
$begingroup$
You can do
>
in place of and
.$endgroup$
– xnor
2 days ago
$begingroup$
@xnor thanks, easy to forget that will work.
$endgroup$
– Jonathan Allan
2 days ago
$begingroup$
@xnor thanks, easy to forget that will work.
$endgroup$
– Jonathan Allan
2 days ago
add a comment |
$begingroup$
Wolfram Language (Mathematica), 47 bytes
Most@FixedPointList[Times@@IntegerDigits@#&,#]&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 47 bytes
Most@FixedPointList[Times@@IntegerDigits@#&,#]&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 47 bytes
Most@FixedPointList[Times@@IntegerDigits@#&,#]&
Try it online!
$endgroup$
Wolfram Language (Mathematica), 47 bytes
Most@FixedPointList[Times@@IntegerDigits@#&,#]&
Try it online!
answered Mar 21 at 14:25
J42161217J42161217
13.5k21252
13.5k21252
add a comment |
add a comment |
$begingroup$
Wolfram Language (Mathematica), 45 bytes
#//.x_/;x>9:>Times@@IntegerDigits@x&&Print@x&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 45 bytes
#//.x_/;x>9:>Times@@IntegerDigits@x&&Print@x&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 45 bytes
#//.x_/;x>9:>Times@@IntegerDigits@x&&Print@x&
Try it online!
$endgroup$
Wolfram Language (Mathematica), 45 bytes
#//.x_/;x>9:>Times@@IntegerDigits@x&&Print@x&
Try it online!
answered Mar 21 at 15:18
J42161217J42161217
13.5k21252
13.5k21252
add a comment |
add a comment |
$begingroup$
Jelly, 4 bytes
DP$Ƭ
Try it online!
Explanation
D | convert to decimal digits
P | take the product
$ | previous two links as a monad
Ƭ | loop until no change, collecting all intermediate results
As a bonus, here's a TIO which will find the numbers with the largest number of steps for a given range of numbers of digits. It scales well even on TIO.
$endgroup$
add a comment |
$begingroup$
Jelly, 4 bytes
DP$Ƭ
Try it online!
Explanation
D | convert to decimal digits
P | take the product
$ | previous two links as a monad
Ƭ | loop until no change, collecting all intermediate results
As a bonus, here's a TIO which will find the numbers with the largest number of steps for a given range of numbers of digits. It scales well even on TIO.
$endgroup$
add a comment |
$begingroup$
Jelly, 4 bytes
DP$Ƭ
Try it online!
Explanation
D | convert to decimal digits
P | take the product
$ | previous two links as a monad
Ƭ | loop until no change, collecting all intermediate results
As a bonus, here's a TIO which will find the numbers with the largest number of steps for a given range of numbers of digits. It scales well even on TIO.
$endgroup$
Jelly, 4 bytes
DP$Ƭ
Try it online!
Explanation
D | convert to decimal digits
P | take the product
$ | previous two links as a monad
Ƭ | loop until no change, collecting all intermediate results
As a bonus, here's a TIO which will find the numbers with the largest number of steps for a given range of numbers of digits. It scales well even on TIO.
edited Mar 21 at 23:30
answered Mar 21 at 15:08
Nick KennedyNick Kennedy
92147
92147
add a comment |
add a comment |
$begingroup$
Julia 0.7, 36 bytes
f(n)=n>9?[n,f(prod(digits(n)))...]:n
Try it online!
$endgroup$
add a comment |
$begingroup$
Julia 0.7, 36 bytes
f(n)=n>9?[n,f(prod(digits(n)))...]:n
Try it online!
$endgroup$
add a comment |
$begingroup$
Julia 0.7, 36 bytes
f(n)=n>9?[n,f(prod(digits(n)))...]:n
Try it online!
$endgroup$
Julia 0.7, 36 bytes
f(n)=n>9?[n,f(prod(digits(n)))...]:n
Try it online!
answered Mar 21 at 14:44
Kirill L.Kirill L.
5,6831525
5,6831525
add a comment |
add a comment |
$begingroup$
PowerShell, 54 bytes
for($a=$args;$a-gt9){$a;$a=("$a"|% t*y)-join"*"|iex}$a
Try it online!
Iterative method that first writes the input argument, then converts it into a string and pipes it into a character array. This array is joined by a single asterisks, and executed as a command with the invoke expression alias. Since this writes Starting number down to the last number greater than 0, (20, in the given test scenario), I add a final $a
to the end to output.
$endgroup$
add a comment |
$begingroup$
PowerShell, 54 bytes
for($a=$args;$a-gt9){$a;$a=("$a"|% t*y)-join"*"|iex}$a
Try it online!
Iterative method that first writes the input argument, then converts it into a string and pipes it into a character array. This array is joined by a single asterisks, and executed as a command with the invoke expression alias. Since this writes Starting number down to the last number greater than 0, (20, in the given test scenario), I add a final $a
to the end to output.
$endgroup$
add a comment |
$begingroup$
PowerShell, 54 bytes
for($a=$args;$a-gt9){$a;$a=("$a"|% t*y)-join"*"|iex}$a
Try it online!
Iterative method that first writes the input argument, then converts it into a string and pipes it into a character array. This array is joined by a single asterisks, and executed as a command with the invoke expression alias. Since this writes Starting number down to the last number greater than 0, (20, in the given test scenario), I add a final $a
to the end to output.
$endgroup$
PowerShell, 54 bytes
for($a=$args;$a-gt9){$a;$a=("$a"|% t*y)-join"*"|iex}$a
Try it online!
Iterative method that first writes the input argument, then converts it into a string and pipes it into a character array. This array is joined by a single asterisks, and executed as a command with the invoke expression alias. Since this writes Starting number down to the last number greater than 0, (20, in the given test scenario), I add a final $a
to the end to output.
edited Mar 21 at 16:12
answered Mar 21 at 15:53
KGlasierKGlasier
1916
1916
add a comment |
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 79 74 68 bytes
void f(int a){Print(a);if(a>9)f((a+"").Aggregate(1,(j,k)=>k%48*j));}
I try to stay away from recursion in C# due to how long the method declaration is, but in this case it saves compared to a loop.
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 79 74 68 bytes
void f(int a){Print(a);if(a>9)f((a+"").Aggregate(1,(j,k)=>k%48*j));}
I try to stay away from recursion in C# due to how long the method declaration is, but in this case it saves compared to a loop.
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 79 74 68 bytes
void f(int a){Print(a);if(a>9)f((a+"").Aggregate(1,(j,k)=>k%48*j));}
I try to stay away from recursion in C# due to how long the method declaration is, but in this case it saves compared to a loop.
Try it online!
$endgroup$
C# (Visual C# Interactive Compiler), 79 74 68 bytes
void f(int a){Print(a);if(a>9)f((a+"").Aggregate(1,(j,k)=>k%48*j));}
I try to stay away from recursion in C# due to how long the method declaration is, but in this case it saves compared to a loop.
Try it online!
edited Mar 21 at 16:32
answered Mar 21 at 15:30
Embodiment of IgnoranceEmbodiment of Ignorance
2,138125
2,138125
add a comment |
add a comment |
$begingroup$
Python 2, 61 62 59 bytes
def f(n):print n;n>9and f(reduce(int.__mul__,map(int,`n`)))
Try it online!
-3 bytes, thanks to Jonathan Allan
$endgroup$
$begingroup$
Doesn't work for inputs that don't end with a 0 on their last iteration, for example 23
$endgroup$
– Embodiment of Ignorance
Mar 21 at 15:40
$begingroup$
int.__mul__
is three bytes less thanlambda a,b:a*b
$endgroup$
– Jonathan Allan
Mar 21 at 17:17
$begingroup$
@JonathanAllan Thanks! I knew there had to be something like that
$endgroup$
– TFeld
Mar 21 at 19:05
$begingroup$
Changef(reduce(int.__mul__,map(int,`n`)))
tof(eval('*'.join(`n`)))
to save 13 bytes.
$endgroup$
– mypetlion
Mar 21 at 20:34
$begingroup$
@mypetlion ...I already did that in another post.
$endgroup$
– Jonathan Allan
Mar 21 at 20:52
add a comment |
$begingroup$
Python 2, 61 62 59 bytes
def f(n):print n;n>9and f(reduce(int.__mul__,map(int,`n`)))
Try it online!
-3 bytes, thanks to Jonathan Allan
$endgroup$
$begingroup$
Doesn't work for inputs that don't end with a 0 on their last iteration, for example 23
$endgroup$
– Embodiment of Ignorance
Mar 21 at 15:40
$begingroup$
int.__mul__
is three bytes less thanlambda a,b:a*b
$endgroup$
– Jonathan Allan
Mar 21 at 17:17
$begingroup$
@JonathanAllan Thanks! I knew there had to be something like that
$endgroup$
– TFeld
Mar 21 at 19:05
$begingroup$
Changef(reduce(int.__mul__,map(int,`n`)))
tof(eval('*'.join(`n`)))
to save 13 bytes.
$endgroup$
– mypetlion
Mar 21 at 20:34
$begingroup$
@mypetlion ...I already did that in another post.
$endgroup$
– Jonathan Allan
Mar 21 at 20:52
add a comment |
$begingroup$
Python 2, 61 62 59 bytes
def f(n):print n;n>9and f(reduce(int.__mul__,map(int,`n`)))
Try it online!
-3 bytes, thanks to Jonathan Allan
$endgroup$
Python 2, 61 62 59 bytes
def f(n):print n;n>9and f(reduce(int.__mul__,map(int,`n`)))
Try it online!
-3 bytes, thanks to Jonathan Allan
edited Mar 21 at 19:07
answered Mar 21 at 15:39
TFeldTFeld
15.9k21449
15.9k21449
$begingroup$
Doesn't work for inputs that don't end with a 0 on their last iteration, for example 23
$endgroup$
– Embodiment of Ignorance
Mar 21 at 15:40
$begingroup$
int.__mul__
is three bytes less thanlambda a,b:a*b
$endgroup$
– Jonathan Allan
Mar 21 at 17:17
$begingroup$
@JonathanAllan Thanks! I knew there had to be something like that
$endgroup$
– TFeld
Mar 21 at 19:05
$begingroup$
Changef(reduce(int.__mul__,map(int,`n`)))
tof(eval('*'.join(`n`)))
to save 13 bytes.
$endgroup$
– mypetlion
Mar 21 at 20:34
$begingroup$
@mypetlion ...I already did that in another post.
$endgroup$
– Jonathan Allan
Mar 21 at 20:52
add a comment |
$begingroup$
Doesn't work for inputs that don't end with a 0 on their last iteration, for example 23
$endgroup$
– Embodiment of Ignorance
Mar 21 at 15:40
$begingroup$
int.__mul__
is three bytes less thanlambda a,b:a*b
$endgroup$
– Jonathan Allan
Mar 21 at 17:17
$begingroup$
@JonathanAllan Thanks! I knew there had to be something like that
$endgroup$
– TFeld
Mar 21 at 19:05
$begingroup$
Changef(reduce(int.__mul__,map(int,`n`)))
tof(eval('*'.join(`n`)))
to save 13 bytes.
$endgroup$
– mypetlion
Mar 21 at 20:34
$begingroup$
@mypetlion ...I already did that in another post.
$endgroup$
– Jonathan Allan
Mar 21 at 20:52
$begingroup$
Doesn't work for inputs that don't end with a 0 on their last iteration, for example 23
$endgroup$
– Embodiment of Ignorance
Mar 21 at 15:40
$begingroup$
Doesn't work for inputs that don't end with a 0 on their last iteration, for example 23
$endgroup$
– Embodiment of Ignorance
Mar 21 at 15:40
$begingroup$
int.__mul__
is three bytes less than lambda a,b:a*b
$endgroup$
– Jonathan Allan
Mar 21 at 17:17
$begingroup$
int.__mul__
is three bytes less than lambda a,b:a*b
$endgroup$
– Jonathan Allan
Mar 21 at 17:17
$begingroup$
@JonathanAllan Thanks! I knew there had to be something like that
$endgroup$
– TFeld
Mar 21 at 19:05
$begingroup$
@JonathanAllan Thanks! I knew there had to be something like that
$endgroup$
– TFeld
Mar 21 at 19:05
$begingroup$
Change
f(reduce(int.__mul__,map(int,`n`)))
to f(eval('*'.join(`n`)))
to save 13 bytes.$endgroup$
– mypetlion
Mar 21 at 20:34
$begingroup$
Change
f(reduce(int.__mul__,map(int,`n`)))
to f(eval('*'.join(`n`)))
to save 13 bytes.$endgroup$
– mypetlion
Mar 21 at 20:34
$begingroup$
@mypetlion ...I already did that in another post.
$endgroup$
– Jonathan Allan
Mar 21 at 20:52
$begingroup$
@mypetlion ...I already did that in another post.
$endgroup$
– Jonathan Allan
Mar 21 at 20:52
add a comment |
$begingroup$
perl 5 (-n
-M5.01
), 32 30 25 bytes
say$_=eval;s/B/*/g&&redo
25 bytes
30 bytes
32 bytes
$endgroup$
$begingroup$
You should mention that this uses-lpF//
$endgroup$
– Grimy
2 days ago
1
$begingroup$
@Grimy i could save 2 bytes without using-lpF//
, updating
$endgroup$
– Nahuel Fouilleul
2 days ago
add a comment |
$begingroup$
perl 5 (-n
-M5.01
), 32 30 25 bytes
say$_=eval;s/B/*/g&&redo
25 bytes
30 bytes
32 bytes
$endgroup$
$begingroup$
You should mention that this uses-lpF//
$endgroup$
– Grimy
2 days ago
1
$begingroup$
@Grimy i could save 2 bytes without using-lpF//
, updating
$endgroup$
– Nahuel Fouilleul
2 days ago
add a comment |
$begingroup$
perl 5 (-n
-M5.01
), 32 30 25 bytes
say$_=eval;s/B/*/g&&redo
25 bytes
30 bytes
32 bytes
$endgroup$
perl 5 (-n
-M5.01
), 32 30 25 bytes
say$_=eval;s/B/*/g&&redo
25 bytes
30 bytes
32 bytes
edited 2 days ago
answered Mar 21 at 16:21
Nahuel FouilleulNahuel Fouilleul
2,905211
2,905211
$begingroup$
You should mention that this uses-lpF//
$endgroup$
– Grimy
2 days ago
1
$begingroup$
@Grimy i could save 2 bytes without using-lpF//
, updating
$endgroup$
– Nahuel Fouilleul
2 days ago
add a comment |
$begingroup$
You should mention that this uses-lpF//
$endgroup$
– Grimy
2 days ago
1
$begingroup$
@Grimy i could save 2 bytes without using-lpF//
, updating
$endgroup$
– Nahuel Fouilleul
2 days ago
$begingroup$
You should mention that this uses
-lpF//
$endgroup$
– Grimy
2 days ago
$begingroup$
You should mention that this uses
-lpF//
$endgroup$
– Grimy
2 days ago
1
1
$begingroup$
@Grimy i could save 2 bytes without using
-lpF//
, updating$endgroup$
– Nahuel Fouilleul
2 days ago
$begingroup$
@Grimy i could save 2 bytes without using
-lpF//
, updating$endgroup$
– Nahuel Fouilleul
2 days ago
add a comment |
$begingroup$
MathGolf, 9 10 bytes
h(ôo▒ε*h(→
Try it online!
Now it correctly handles inputs that are single digits. Not perfect, but at least it is correct.
Explanation
h( check length of input number and decrease by 1
ö → while true with pop using the next 6 operators
p print with newline
▒ split to list of chars/digits
ε* reduce list by multiplication
h( length of TOS without popping, subtracted by 1 (exits when len(TOS) == 1)
$endgroup$
$begingroup$
The output for a single digit input should be one copy of the number - clarified in the comments
$endgroup$
– dzaima
Mar 21 at 18:38
$begingroup$
@dzaima I'll look into it, and update the answer when it's solved
$endgroup$
– maxb
2 days ago
add a comment |
$begingroup$
MathGolf, 9 10 bytes
h(ôo▒ε*h(→
Try it online!
Now it correctly handles inputs that are single digits. Not perfect, but at least it is correct.
Explanation
h( check length of input number and decrease by 1
ö → while true with pop using the next 6 operators
p print with newline
▒ split to list of chars/digits
ε* reduce list by multiplication
h( length of TOS without popping, subtracted by 1 (exits when len(TOS) == 1)
$endgroup$
$begingroup$
The output for a single digit input should be one copy of the number - clarified in the comments
$endgroup$
– dzaima
Mar 21 at 18:38
$begingroup$
@dzaima I'll look into it, and update the answer when it's solved
$endgroup$
– maxb
2 days ago
add a comment |
$begingroup$
MathGolf, 9 10 bytes
h(ôo▒ε*h(→
Try it online!
Now it correctly handles inputs that are single digits. Not perfect, but at least it is correct.
Explanation
h( check length of input number and decrease by 1
ö → while true with pop using the next 6 operators
p print with newline
▒ split to list of chars/digits
ε* reduce list by multiplication
h( length of TOS without popping, subtracted by 1 (exits when len(TOS) == 1)
$endgroup$
MathGolf, 9 10 bytes
h(ôo▒ε*h(→
Try it online!
Now it correctly handles inputs that are single digits. Not perfect, but at least it is correct.
Explanation
h( check length of input number and decrease by 1
ö → while true with pop using the next 6 operators
p print with newline
▒ split to list of chars/digits
ε* reduce list by multiplication
h( length of TOS without popping, subtracted by 1 (exits when len(TOS) == 1)
edited 2 days ago
Scott Milner
1,676521
1,676521
answered Mar 21 at 15:12
maxbmaxb
3,30811232
3,30811232
$begingroup$
The output for a single digit input should be one copy of the number - clarified in the comments
$endgroup$
– dzaima
Mar 21 at 18:38
$begingroup$
@dzaima I'll look into it, and update the answer when it's solved
$endgroup$
– maxb
2 days ago
add a comment |
$begingroup$
The output for a single digit input should be one copy of the number - clarified in the comments
$endgroup$
– dzaima
Mar 21 at 18:38
$begingroup$
@dzaima I'll look into it, and update the answer when it's solved
$endgroup$
– maxb
2 days ago
$begingroup$
The output for a single digit input should be one copy of the number - clarified in the comments
$endgroup$
– dzaima
Mar 21 at 18:38
$begingroup$
The output for a single digit input should be one copy of the number - clarified in the comments
$endgroup$
– dzaima
Mar 21 at 18:38
$begingroup$
@dzaima I'll look into it, and update the answer when it's solved
$endgroup$
– maxb
2 days ago
$begingroup$
@dzaima I'll look into it, and update the answer when it's solved
$endgroup$
– maxb
2 days ago
add a comment |
$begingroup$
JavaScript (ES6), 45 bytes
Returns an array of integers.
f=n=>[n,...n>9?f(eval([...n+''].join`*`)):]
Try it online!
$endgroup$
add a comment |
$begingroup$
JavaScript (ES6), 45 bytes
Returns an array of integers.
f=n=>[n,...n>9?f(eval([...n+''].join`*`)):]
Try it online!
$endgroup$
add a comment |
$begingroup$
JavaScript (ES6), 45 bytes
Returns an array of integers.
f=n=>[n,...n>9?f(eval([...n+''].join`*`)):]
Try it online!
$endgroup$
JavaScript (ES6), 45 bytes
Returns an array of integers.
f=n=>[n,...n>9?f(eval([...n+''].join`*`)):]
Try it online!
edited Mar 21 at 14:29
answered Mar 21 at 14:24
ArnauldArnauld
79.6k796330
79.6k796330
add a comment |
add a comment |
$begingroup$
PowerShell, 51 bytes
filter f{$_
if($_-gt9){("$_"|% t*y)-join'*'|iex|f}}
Try it online!
$endgroup$
add a comment |
$begingroup$
PowerShell, 51 bytes
filter f{$_
if($_-gt9){("$_"|% t*y)-join'*'|iex|f}}
Try it online!
$endgroup$
add a comment |
$begingroup$
PowerShell, 51 bytes
filter f{$_
if($_-gt9){("$_"|% t*y)-join'*'|iex|f}}
Try it online!
$endgroup$
PowerShell, 51 bytes
filter f{$_
if($_-gt9){("$_"|% t*y)-join'*'|iex|f}}
Try it online!
answered Mar 21 at 16:31
mazzymazzy
2,8951317
2,8951317
add a comment |
add a comment |
$begingroup$
Haskell, 45 bytes
f n=n:[x|n>9,x<-f$product$read.pure<$>show n]
Try it online!
$endgroup$
add a comment |
$begingroup$
Haskell, 45 bytes
f n=n:[x|n>9,x<-f$product$read.pure<$>show n]
Try it online!
$endgroup$
add a comment |
$begingroup$
Haskell, 45 bytes
f n=n:[x|n>9,x<-f$product$read.pure<$>show n]
Try it online!
$endgroup$
Haskell, 45 bytes
f n=n:[x|n>9,x<-f$product$read.pure<$>show n]
Try it online!
answered Mar 21 at 17:42
niminimi
32.4k32389
32.4k32389
add a comment |
add a comment |
$begingroup$
PHP, 63 bytes
<?=$n=$argn;while($n>9)echo"
",$n=array_product(str_split($n));
Iterative version, call with php -nF
input from STDIN
.
Try it online!
PHP, 72 71 bytes
function h($n){echo"$n
",($n=array_product(str_split($n)))>9?h($n):$n;}
Try it online!
Recursive version, as function.
Input: 277777788888899
277777788888899
4996238671872
438939648
4478976
338688
27648
2688
768
336
54
20
0
Input: 23
23
6
$endgroup$
add a comment |
$begingroup$
PHP, 63 bytes
<?=$n=$argn;while($n>9)echo"
",$n=array_product(str_split($n));
Iterative version, call with php -nF
input from STDIN
.
Try it online!
PHP, 72 71 bytes
function h($n){echo"$n
",($n=array_product(str_split($n)))>9?h($n):$n;}
Try it online!
Recursive version, as function.
Input: 277777788888899
277777788888899
4996238671872
438939648
4478976
338688
27648
2688
768
336
54
20
0
Input: 23
23
6
$endgroup$
add a comment |
$begingroup$
PHP, 63 bytes
<?=$n=$argn;while($n>9)echo"
",$n=array_product(str_split($n));
Iterative version, call with php -nF
input from STDIN
.
Try it online!
PHP, 72 71 bytes
function h($n){echo"$n
",($n=array_product(str_split($n)))>9?h($n):$n;}
Try it online!
Recursive version, as function.
Input: 277777788888899
277777788888899
4996238671872
438939648
4478976
338688
27648
2688
768
336
54
20
0
Input: 23
23
6
$endgroup$
PHP, 63 bytes
<?=$n=$argn;while($n>9)echo"
",$n=array_product(str_split($n));
Iterative version, call with php -nF
input from STDIN
.
Try it online!
PHP, 72 71 bytes
function h($n){echo"$n
",($n=array_product(str_split($n)))>9?h($n):$n;}
Try it online!
Recursive version, as function.
Input: 277777788888899
277777788888899
4996238671872
438939648
4478976
338688
27648
2688
768
336
54
20
0
Input: 23
23
6
edited Mar 21 at 18:06
answered Mar 21 at 16:20
gwaughgwaugh
1,948515
1,948515
add a comment |
add a comment |
$begingroup$
J, 16 bytes
([:*/,.&.":)^:a:
Try it online!
$endgroup$
add a comment |
$begingroup$
J, 16 bytes
([:*/,.&.":)^:a:
Try it online!
$endgroup$
add a comment |
$begingroup$
J, 16 bytes
([:*/,.&.":)^:a:
Try it online!
$endgroup$
J, 16 bytes
([:*/,.&.":)^:a:
Try it online!
answered Mar 21 at 19:05
Galen IvanovGalen Ivanov
7,24211034
7,24211034
add a comment |
add a comment |
$begingroup$
Ruby, 38 35 34 bytes
f=->n{p(n)>9&&f[eval n.digits*?*]}
Try it online!
1 byte saved by by G B.
$endgroup$
add a comment |
$begingroup$
Ruby, 38 35 34 bytes
f=->n{p(n)>9&&f[eval n.digits*?*]}
Try it online!
1 byte saved by by G B.
$endgroup$
add a comment |
$begingroup$
Ruby, 38 35 34 bytes
f=->n{p(n)>9&&f[eval n.digits*?*]}
Try it online!
1 byte saved by by G B.
$endgroup$
Ruby, 38 35 34 bytes
f=->n{p(n)>9&&f[eval n.digits*?*]}
Try it online!
1 byte saved by by G B.
edited 2 days ago
answered Mar 21 at 14:29
Kirill L.Kirill L.
5,6831525
5,6831525
add a comment |
add a comment |
$begingroup$
Brachylog, 7 bytes
ẉ?Ḋ|ẹ×↰
Try it online!
Explanation
ẉ Write the input followed by a linebreak
?Ḋ If the input is a single digit, then it's over
| Otherwise
ẹ Split the input into a list of digits
× Multiply them together
↰ Recursive call with the result of the multiplication as input
$endgroup$
$begingroup$
I gave it a try myself. Forgot about the Ḋ. The rest i had the same.
$endgroup$
– Kroppeb
Mar 21 at 19:33
add a comment |
$begingroup$
Brachylog, 7 bytes
ẉ?Ḋ|ẹ×↰
Try it online!
Explanation
ẉ Write the input followed by a linebreak
?Ḋ If the input is a single digit, then it's over
| Otherwise
ẹ Split the input into a list of digits
× Multiply them together
↰ Recursive call with the result of the multiplication as input
$endgroup$
$begingroup$
I gave it a try myself. Forgot about the Ḋ. The rest i had the same.
$endgroup$
– Kroppeb
Mar 21 at 19:33
add a comment |
$begingroup$
Brachylog, 7 bytes
ẉ?Ḋ|ẹ×↰
Try it online!
Explanation
ẉ Write the input followed by a linebreak
?Ḋ If the input is a single digit, then it's over
| Otherwise
ẹ Split the input into a list of digits
× Multiply them together
↰ Recursive call with the result of the multiplication as input
$endgroup$
Brachylog, 7 bytes
ẉ?Ḋ|ẹ×↰
Try it online!
Explanation
ẉ Write the input followed by a linebreak
?Ḋ If the input is a single digit, then it's over
| Otherwise
ẹ Split the input into a list of digits
× Multiply them together
↰ Recursive call with the result of the multiplication as input
answered Mar 21 at 14:32
FatalizeFatalize
27.8k448136
27.8k448136
$begingroup$
I gave it a try myself. Forgot about the Ḋ. The rest i had the same.
$endgroup$
– Kroppeb
Mar 21 at 19:33
add a comment |
$begingroup$
I gave it a try myself. Forgot about the Ḋ. The rest i had the same.
$endgroup$
– Kroppeb
Mar 21 at 19:33
$begingroup$
I gave it a try myself. Forgot about the Ḋ. The rest i had the same.
$endgroup$
– Kroppeb
Mar 21 at 19:33
$begingroup$
I gave it a try myself. Forgot about the Ḋ. The rest i had the same.
$endgroup$
– Kroppeb
Mar 21 at 19:33
add a comment |
$begingroup$
JavaScript (Babel Node), 46 bytes
f=a=>a>9?[a,...f(eval([...a+''].join`*`))]:[a]
Try it online!
JavaScript (Babel Node), 44 bytes
If the input can be taken as String
f=a=>a>9?[a,...f(''+eval([...a].join`*`))]:a
Try it online!
$endgroup$
$begingroup$
@Arnauld Yes, I just edited and added the wrong code. Im still looking for something using only strings instead arrays
$endgroup$
– Luis felipe De jesus Munoz
Mar 21 at 15:12
add a comment |
$begingroup$
JavaScript (Babel Node), 46 bytes
f=a=>a>9?[a,...f(eval([...a+''].join`*`))]:[a]
Try it online!
JavaScript (Babel Node), 44 bytes
If the input can be taken as String
f=a=>a>9?[a,...f(''+eval([...a].join`*`))]:a
Try it online!
$endgroup$
$begingroup$
@Arnauld Yes, I just edited and added the wrong code. Im still looking for something using only strings instead arrays
$endgroup$
– Luis felipe De jesus Munoz
Mar 21 at 15:12
add a comment |
$begingroup$
JavaScript (Babel Node), 46 bytes
f=a=>a>9?[a,...f(eval([...a+''].join`*`))]:[a]
Try it online!
JavaScript (Babel Node), 44 bytes
If the input can be taken as String
f=a=>a>9?[a,...f(''+eval([...a].join`*`))]:a
Try it online!
$endgroup$
JavaScript (Babel Node), 46 bytes
f=a=>a>9?[a,...f(eval([...a+''].join`*`))]:[a]
Try it online!
JavaScript (Babel Node), 44 bytes
If the input can be taken as String
f=a=>a>9?[a,...f(''+eval([...a].join`*`))]:a
Try it online!
edited Mar 21 at 15:11
answered Mar 21 at 14:29
Luis felipe De jesus MunozLuis felipe De jesus Munoz
5,67821671
5,67821671
$begingroup$
@Arnauld Yes, I just edited and added the wrong code. Im still looking for something using only strings instead arrays
$endgroup$
– Luis felipe De jesus Munoz
Mar 21 at 15:12
add a comment |
$begingroup$
@Arnauld Yes, I just edited and added the wrong code. Im still looking for something using only strings instead arrays
$endgroup$
– Luis felipe De jesus Munoz
Mar 21 at 15:12
$begingroup$
@Arnauld Yes, I just edited and added the wrong code. Im still looking for something using only strings instead arrays
$endgroup$
– Luis felipe De jesus Munoz
Mar 21 at 15:12
$begingroup$
@Arnauld Yes, I just edited and added the wrong code. Im still looking for something using only strings instead arrays
$endgroup$
– Luis felipe De jesus Munoz
Mar 21 at 15:12
add a comment |
$begingroup$
PowerShell, 64 59 bytes
for($a="$args";9-lt$a){$a;$a="$(($a|% t*y)-join'*'|iex)"}$a
Try it online!
Iterative method. Takes input and stores it into $a
, then enters a for
loop so long as the length of $a
is two or more (i.e., it's bigger than 9
). Inside the loop we output $a
and then recalculate it by converting it t
oCharArray
, join
ing it together with *
, and then iex
(short for Invoke-Expression
and similar to eval
). Once we're out of the loop, we have a single digit left to print, so we place $a
onto the pipeline again.
-5 bytes thanks to KGlasier.
$endgroup$
$begingroup$
You could use the comparison9-lt$a
instead of$a.length-1
to save 5 bytes. And if you didn't go string based the whole time you could cut off a decent chunk. Check out my powershell attempt if you want!
$endgroup$
– KGlasier
Mar 21 at 16:22
add a comment |
$begingroup$
PowerShell, 64 59 bytes
for($a="$args";9-lt$a){$a;$a="$(($a|% t*y)-join'*'|iex)"}$a
Try it online!
Iterative method. Takes input and stores it into $a
, then enters a for
loop so long as the length of $a
is two or more (i.e., it's bigger than 9
). Inside the loop we output $a
and then recalculate it by converting it t
oCharArray
, join
ing it together with *
, and then iex
(short for Invoke-Expression
and similar to eval
). Once we're out of the loop, we have a single digit left to print, so we place $a
onto the pipeline again.
-5 bytes thanks to KGlasier.
$endgroup$
$begingroup$
You could use the comparison9-lt$a
instead of$a.length-1
to save 5 bytes. And if you didn't go string based the whole time you could cut off a decent chunk. Check out my powershell attempt if you want!
$endgroup$
– KGlasier
Mar 21 at 16:22
add a comment |
$begingroup$
PowerShell, 64 59 bytes
for($a="$args";9-lt$a){$a;$a="$(($a|% t*y)-join'*'|iex)"}$a
Try it online!
Iterative method. Takes input and stores it into $a
, then enters a for
loop so long as the length of $a
is two or more (i.e., it's bigger than 9
). Inside the loop we output $a
and then recalculate it by converting it t
oCharArray
, join
ing it together with *
, and then iex
(short for Invoke-Expression
and similar to eval
). Once we're out of the loop, we have a single digit left to print, so we place $a
onto the pipeline again.
-5 bytes thanks to KGlasier.
$endgroup$
PowerShell, 64 59 bytes
for($a="$args";9-lt$a){$a;$a="$(($a|% t*y)-join'*'|iex)"}$a
Try it online!
Iterative method. Takes input and stores it into $a
, then enters a for
loop so long as the length of $a
is two or more (i.e., it's bigger than 9
). Inside the loop we output $a
and then recalculate it by converting it t
oCharArray
, join
ing it together with *
, and then iex
(short for Invoke-Expression
and similar to eval
). Once we're out of the loop, we have a single digit left to print, so we place $a
onto the pipeline again.
-5 bytes thanks to KGlasier.
edited Mar 21 at 16:29
answered Mar 21 at 14:49
AdmBorkBorkAdmBorkBork
27.5k466237
27.5k466237
$begingroup$
You could use the comparison9-lt$a
instead of$a.length-1
to save 5 bytes. And if you didn't go string based the whole time you could cut off a decent chunk. Check out my powershell attempt if you want!
$endgroup$
– KGlasier
Mar 21 at 16:22
add a comment |
$begingroup$
You could use the comparison9-lt$a
instead of$a.length-1
to save 5 bytes. And if you didn't go string based the whole time you could cut off a decent chunk. Check out my powershell attempt if you want!
$endgroup$
– KGlasier
Mar 21 at 16:22
$begingroup$
You could use the comparison
9-lt$a
instead of $a.length-1
to save 5 bytes. And if you didn't go string based the whole time you could cut off a decent chunk. Check out my powershell attempt if you want!$endgroup$
– KGlasier
Mar 21 at 16:22
$begingroup$
You could use the comparison
9-lt$a
instead of $a.length-1
to save 5 bytes. And if you didn't go string based the whole time you could cut off a decent chunk. Check out my powershell attempt if you want!$endgroup$
– KGlasier
Mar 21 at 16:22
add a comment |
$begingroup$
APL(NARS), 19 chars, 38 bytes
{⍵≤9:⍵⋄∇×/⍎¨⍕⍵⊣⎕←⍵}
test:
f←{⍵≤9:⍵⋄∇×/⍎¨⍕⍵⊣⎕←⍵}
f 23
23
6
f 27648
27648
2688
768
336
54
20
0
$endgroup$
add a comment |
$begingroup$
APL(NARS), 19 chars, 38 bytes
{⍵≤9:⍵⋄∇×/⍎¨⍕⍵⊣⎕←⍵}
test:
f←{⍵≤9:⍵⋄∇×/⍎¨⍕⍵⊣⎕←⍵}
f 23
23
6
f 27648
27648
2688
768
336
54
20
0
$endgroup$
add a comment |
$begingroup$
APL(NARS), 19 chars, 38 bytes
{⍵≤9:⍵⋄∇×/⍎¨⍕⍵⊣⎕←⍵}
test:
f←{⍵≤9:⍵⋄∇×/⍎¨⍕⍵⊣⎕←⍵}
f 23
23
6
f 27648
27648
2688
768
336
54
20
0
$endgroup$
APL(NARS), 19 chars, 38 bytes
{⍵≤9:⍵⋄∇×/⍎¨⍕⍵⊣⎕←⍵}
test:
f←{⍵≤9:⍵⋄∇×/⍎¨⍕⍵⊣⎕←⍵}
f 23
23
6
f 27648
27648
2688
768
336
54
20
0
answered Mar 21 at 16:41
RosLuPRosLuP
2,276514
2,276514
add a comment |
add a comment |
$begingroup$
Charcoal, 13 bytes
θW⊖Lθ«≔IΠθθ⸿θ
Try it online! Link is to verbose version of code. Explanation:
θ
Print the input for the first time.
W⊖Lθ«
Repeat while the length of the input is not 1.
≔IΠθθ
Replace the input with its digital product cast to string.
⸿θ
Print the input on a new line.
$endgroup$
add a comment |
$begingroup$
Charcoal, 13 bytes
θW⊖Lθ«≔IΠθθ⸿θ
Try it online! Link is to verbose version of code. Explanation:
θ
Print the input for the first time.
W⊖Lθ«
Repeat while the length of the input is not 1.
≔IΠθθ
Replace the input with its digital product cast to string.
⸿θ
Print the input on a new line.
$endgroup$
add a comment |
$begingroup$
Charcoal, 13 bytes
θW⊖Lθ«≔IΠθθ⸿θ
Try it online! Link is to verbose version of code. Explanation:
θ
Print the input for the first time.
W⊖Lθ«
Repeat while the length of the input is not 1.
≔IΠθθ
Replace the input with its digital product cast to string.
⸿θ
Print the input on a new line.
$endgroup$
Charcoal, 13 bytes
θW⊖Lθ«≔IΠθθ⸿θ
Try it online! Link is to verbose version of code. Explanation:
θ
Print the input for the first time.
W⊖Lθ«
Repeat while the length of the input is not 1.
≔IΠθθ
Replace the input with its digital product cast to string.
⸿θ
Print the input on a new line.
answered Mar 21 at 16:48
NeilNeil
82k745178
82k745178
add a comment |
add a comment |
$begingroup$
C (gcc), 58 bytes
f(n,t){for(;n=printf("%dn",t=n)>2;)for(;n*=t%10,t/=10;);}
Try it online!
Iterative approach turns out to be 1 byte shorter.
f(n,t){
for(;n=printf("%dn",t=n) //print and update current number
>2;) //until only one digit is printed
for(;n*=t%10,t/=10;); //n*= product of digits of t (step)
}
C (gcc), 61 59 bytes (recursive)
f(n){printf("%dn",n)>2&&f(p(n));}p(n){n=n?n%10*p(n/10):1;}
Try it online!
Recursion seems to be shorter than iteration for both print and step...
$endgroup$
add a comment |
$begingroup$
C (gcc), 58 bytes
f(n,t){for(;n=printf("%dn",t=n)>2;)for(;n*=t%10,t/=10;);}
Try it online!
Iterative approach turns out to be 1 byte shorter.
f(n,t){
for(;n=printf("%dn",t=n) //print and update current number
>2;) //until only one digit is printed
for(;n*=t%10,t/=10;); //n*= product of digits of t (step)
}
C (gcc), 61 59 bytes (recursive)
f(n){printf("%dn",n)>2&&f(p(n));}p(n){n=n?n%10*p(n/10):1;}
Try it online!
Recursion seems to be shorter than iteration for both print and step...
$endgroup$
add a comment |
$begingroup$
C (gcc), 58 bytes
f(n,t){for(;n=printf("%dn",t=n)>2;)for(;n*=t%10,t/=10;);}
Try it online!
Iterative approach turns out to be 1 byte shorter.
f(n,t){
for(;n=printf("%dn",t=n) //print and update current number
>2;) //until only one digit is printed
for(;n*=t%10,t/=10;); //n*= product of digits of t (step)
}
C (gcc), 61 59 bytes (recursive)
f(n){printf("%dn",n)>2&&f(p(n));}p(n){n=n?n%10*p(n/10):1;}
Try it online!
Recursion seems to be shorter than iteration for both print and step...
$endgroup$
C (gcc), 58 bytes
f(n,t){for(;n=printf("%dn",t=n)>2;)for(;n*=t%10,t/=10;);}
Try it online!
Iterative approach turns out to be 1 byte shorter.
f(n,t){
for(;n=printf("%dn",t=n) //print and update current number
>2;) //until only one digit is printed
for(;n*=t%10,t/=10;); //n*= product of digits of t (step)
}
C (gcc), 61 59 bytes (recursive)
f(n){printf("%dn",n)>2&&f(p(n));}p(n){n=n?n%10*p(n/10):1;}
Try it online!
Recursion seems to be shorter than iteration for both print and step...
edited 21 hours ago
answered 2 days ago
attinatattinat
4105
4105
add a comment |
add a comment |
$begingroup$
Retina, 24 bytes
.+~(`
.
$&$*
^
.+¶$$.(
Try it online! Explanation:
.+~(`
Print the current value on its own line at the start of every loop until it stops changing and don't print the unchanged value twice. Evaluate the current value at the end of each loop.
.
$&$*
Add a *
after each digit.
^
.+¶$$.(
Finish turning the input into an expression that evaluates to the digital product.
Just for the record, Retina can do this in one line (25 bytes):
.+"¶"<~[".+¶$.("|'*]'*L`.
$endgroup$
add a comment |
$begingroup$
Retina, 24 bytes
.+~(`
.
$&$*
^
.+¶$$.(
Try it online! Explanation:
.+~(`
Print the current value on its own line at the start of every loop until it stops changing and don't print the unchanged value twice. Evaluate the current value at the end of each loop.
.
$&$*
Add a *
after each digit.
^
.+¶$$.(
Finish turning the input into an expression that evaluates to the digital product.
Just for the record, Retina can do this in one line (25 bytes):
.+"¶"<~[".+¶$.("|'*]'*L`.
$endgroup$
add a comment |
$begingroup$
Retina, 24 bytes
.+~(`
.
$&$*
^
.+¶$$.(
Try it online! Explanation:
.+~(`
Print the current value on its own line at the start of every loop until it stops changing and don't print the unchanged value twice. Evaluate the current value at the end of each loop.
.
$&$*
Add a *
after each digit.
^
.+¶$$.(
Finish turning the input into an expression that evaluates to the digital product.
Just for the record, Retina can do this in one line (25 bytes):
.+"¶"<~[".+¶$.("|'*]'*L`.
$endgroup$
Retina, 24 bytes
.+~(`
.
$&$*
^
.+¶$$.(
Try it online! Explanation:
.+~(`
Print the current value on its own line at the start of every loop until it stops changing and don't print the unchanged value twice. Evaluate the current value at the end of each loop.
.
$&$*
Add a *
after each digit.
^
.+¶$$.(
Finish turning the input into an expression that evaluates to the digital product.
Just for the record, Retina can do this in one line (25 bytes):
.+"¶"<~[".+¶$.("|'*]'*L`.
answered Mar 21 at 17:01
NeilNeil
82k745178
82k745178
add a comment |
add a comment |
$begingroup$
Java, 112 bytes
"Lossy conversion" thanks Java for the extra ~15 bytes
Obligatory stream abuse recursion answer
long f(long n){System.out.println(n);return n<10?n:f((n+"").chars().mapToLong(i->i).reduce(1,(x,y)->x*(y-48)));}
Try it online
$endgroup$
$begingroup$
I'm pretty sure you only need to supportint
$endgroup$
– Embodiment of Ignorance
2 days ago
$begingroup$
@EmbodimentofIgnorance then it fails for277777788888899
since4996238671872
is too large for an int
$endgroup$
– Benjamin Urquhart
yesterday
add a comment |
$begingroup$
Java, 112 bytes
"Lossy conversion" thanks Java for the extra ~15 bytes
Obligatory stream abuse recursion answer
long f(long n){System.out.println(n);return n<10?n:f((n+"").chars().mapToLong(i->i).reduce(1,(x,y)->x*(y-48)));}
Try it online
$endgroup$
$begingroup$
I'm pretty sure you only need to supportint
$endgroup$
– Embodiment of Ignorance
2 days ago
$begingroup$
@EmbodimentofIgnorance then it fails for277777788888899
since4996238671872
is too large for an int
$endgroup$
– Benjamin Urquhart
yesterday
add a comment |
$begingroup$
Java, 112 bytes
"Lossy conversion" thanks Java for the extra ~15 bytes
Obligatory stream abuse recursion answer
long f(long n){System.out.println(n);return n<10?n:f((n+"").chars().mapToLong(i->i).reduce(1,(x,y)->x*(y-48)));}
Try it online
$endgroup$
Java, 112 bytes
"Lossy conversion" thanks Java for the extra ~15 bytes
Obligatory stream abuse recursion answer
long f(long n){System.out.println(n);return n<10?n:f((n+"").chars().mapToLong(i->i).reduce(1,(x,y)->x*(y-48)));}
Try it online
answered Mar 21 at 19:39
Benjamin UrquhartBenjamin Urquhart
3407
3407
$begingroup$
I'm pretty sure you only need to supportint
$endgroup$
– Embodiment of Ignorance
2 days ago
$begingroup$
@EmbodimentofIgnorance then it fails for277777788888899
since4996238671872
is too large for an int
$endgroup$
– Benjamin Urquhart
yesterday
add a comment |
$begingroup$
I'm pretty sure you only need to supportint
$endgroup$
– Embodiment of Ignorance
2 days ago
$begingroup$
@EmbodimentofIgnorance then it fails for277777788888899
since4996238671872
is too large for an int
$endgroup$
– Benjamin Urquhart
yesterday
$begingroup$
I'm pretty sure you only need to support
int
$endgroup$
– Embodiment of Ignorance
2 days ago
$begingroup$
I'm pretty sure you only need to support
int
$endgroup$
– Embodiment of Ignorance
2 days ago
$begingroup$
@EmbodimentofIgnorance then it fails for
277777788888899
since 4996238671872
is too large for an int$endgroup$
– Benjamin Urquhart
yesterday
$begingroup$
@EmbodimentofIgnorance then it fails for
277777788888899
since 4996238671872
is too large for an int$endgroup$
– Benjamin Urquhart
yesterday
add a comment |
1 2
next
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f181958%2fmultiplicative-persistence%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
8bTeWhs 7TZFg,SPo4N6LwjEQJ0FfoHuNCv
$begingroup$
Bonus: find a new record: smallest number with the largest number of steps. Caveat: conjecture has it that 11 is the largest possible.
$endgroup$
– SQB
Mar 21 at 14:31
7
$begingroup$
You probably should include a few more tests cases that do not end with $0$.
$endgroup$
– Arnauld
Mar 21 at 14:33
$begingroup$
Came to make this post, found it already existing, gg
$endgroup$
– cat
Mar 21 at 14:55
$begingroup$
is a single digit valid input?
$endgroup$
– dzaima
Mar 21 at 18:30
1
$begingroup$
In the Numberphile video, Matt Parker states that searches have been done to several hundred digits.
$endgroup$
– HardScale
Mar 21 at 21:46