29
The winner (pretty obviously) is Dennis ♦, who used Jelly with 10 bytes!
This challenge will still be up here, however results won't be taken anymore.
The powertrain of a number is a concept by John Conway (who is also notable for making Conway's Game of Life, but that's not the point). It is defined as so:
For any number ..., the powertrain of the number is ... (i.e. every 2nd digit, from left to right, is a power of the digit before that). This process is repeated until the result is a single digit.
EXAMPLES:
2592 => (2^5)(9^2) = 2592 <= Cannot be further decomposed
135 => (1^3)5 = 5
1234 => (1^2)(3^4) = 81 => (8^1) = 8
1100 => (1^1)(0^0) = 1 # (0^0) = 1
-42 => -42 # Negative numbers output the input
Your challenge is, for any number n
in the input, return powertrain(n)
(i.e. n
after the powertrain decomposition is finished) as output.
This is code golf, so shortest amount of bytes wins.
DISCLAIMER-THINGS:
- You can have an odd number of digits in the input, the last digit just won't have a power.
- 0^0 is 1, because if it was 0, then a lot of numbers would instantly collapse to 0 or 1.
- If the number is indestructible in any part of the computation process (e.g. if it ends up with
2592
), then you can just output the number. - If the input is
< 10
(i.e. all single digit numbers and negatives), output the input.
I'll probably announce a winner after a few hours days.
Current leaderboard:
- Jelly (Dennis ♦): 10
- Pyth (DenkerAffe): 16
- MATL (Don Muesli): 21
- Perl (Ton Hospel): 42
- Haskell (Damien): 64
- Javascript ES6 (edc65): 71
- Mathematica (murphy): 74
- Mathematica (LegionMammal978) and Haskell (Renzeee): 77
- Python 2 (mathmandan): 111
- Python 3 (Erwan): 161
- Java 8 (Blue): 229
- Oracle SQL 11.2 (Jeto): 456
- Befunge '93 (Lex): 490
Some more test cases would be appreciated. – Mego – 2016-03-08T07:34:09.837
So the input will have 4 digits max? – Denker – 2016-03-08T07:42:08.383
@DenkerAffe No, there is no bound to the digits. They can be as long as you want. The examples were just for simplicity (because I can't be bothered to work out really long ones). – clismique – 2016-03-08T07:42:59.913
7What if a cycle is reached, but the period of the cycle is not 1, or the input number is not part of the cycle? – feersum – 2016-03-08T07:44:15.710
You can output the repeating number. For loops of numbers, I'm certain there aren't any within the realms of feasibility, so you can output whatever, really. Also, it's left to right - I am such an idiot, it's actually not funny. – clismique – 2016-03-08T07:55:22.743
1"I'm certain there aren't any within the realms of feasibility". Can we assume it will never happen? I.e. allowing the loop to go on forever if a cycle of period > 1 is reached? – Stewie Griffin – 2016-03-08T08:01:03.277
@StewieGriffin There haven't been any found so far. Then again, Google gives results of motor vehicles when I search up "powertrain", so... you can assume it never happens. – clismique – 2016-03-08T08:02:45.743
6Proposed test cases:
1100
and-42
It's easy to miss rules about edge cases if the do not show up in the test cases. – Dennis – 2016-03-08T13:24:29.653What exactly is
powertrain(n)
? Is it a number, a list of numbers, or a sequence of computations? The output format is unclear from the spec. – Zgarb – 2016-03-08T15:31:11.737@Zgarb It's just the number going through the powertrain. I couldn't think of a better way to describe it, but it's not a function or anything. – clismique – 2016-03-09T01:21:52.863
24547284284866560000000000 also has a period of 1. – Ian Miller – 2016-03-09T13:07:15.007
But 24547284284866560000000000 is so unfeasibly large that no language has the capacity to do that (also, that is why I put the
0^0 = 1
rule, coincidentally). – clismique – 2016-03-10T09:58:40.323