Find the powertrain!
Haskell, 67 64 bytes
(>>=(==))>>=until$p.show is an unnamed function taking an integer as input and returning its powertrain.
Saved 3 bytes thanks to Zgarb
p(x:y:r)=p[x]^p[y]*p r;p[]=1;p x=read x
(>>=(==))>>=until$p.show
Perl, 42 48 bytes
Include +2 for -lp
(you can drop the -l
too but I like newlines)
Run with input on STDIN, e.g.
perl -lp powertrain.pl <<< 1234
powertrain.pl
:
s/\B/1&pos?"**":"*"/eg until++$.>($_=eval)
(on older perls you can also drop the space between the regex and until)
This won't be able to handle the fixed point 24547284284866560000000000
but that large a value won't work anyways because by that time perl switched to exponential notation.
The above version is will in fact work fast (at most 2592
loops) for all numbers that perl can represent without using exponential notation since it is proven that there are no fixed points between 2592
and 24547284284866560000000000
(https://oeis.org/A135385)
This does however assume something as yet unproven. In principle there could be a reduction that takes more than X=10^7
steps (it is conjectured that no non-fixed point takes more than 16 steps, https://oeis.org/A133503) whose value dips below X
(but above 10^7
) and then goes up again. If that is the case I must fall back to:
s/\B/1&pos?"**":"*"/eg until$s{$_=eval}++||/-/
Explanation
The code works by putting **
and *
(alternating) between the digits
s/\B/1&pos?"**":"*"/eg
so 2592
becomes 2**5*9**2
and 12345
becomes 1**2*3**4*5
. These are
valid perl expressions that can be evaluated with
$_ = eval
(0**0
is 1
in perl). Then just put a loop around that with a counter that makes it expire. Since except for the fixed points the values go down extremely quickly the powertrain series converges before the counter gets a chance to really get going
Jelly, 15 14 12 10 bytes
Ds2*/€Pµ³¡
Try it online!
How it works
Ds2*/€Pµ³¡ Main link. Argument: n
D Convert n into the array of its decimal digits.
s2 Split into pairs of digits.
*/€ Reduce each pair by exponentiation.
P Take the product of the resulting powers.
µ Push the preceding chain as a link, and start a new one.
³¡ Execute the link n times and return the last result.