For a given list of number \$[x_1, x_2, x_3, ..., x_n]\$ find the last digit of \$x_1 ^{x_2 ^ {x_3 ^ {\dots ^ {x_n}}}}\$ Example:
[3, 4, 2] == 1
[4, 3, 2] == 4
[4, 3, 1] == 4
[5, 3, 2] == 5
Because \$3 ^ {(4 ^ 2)} = 3 ^ {16} = 43046721\$.
Because \$4 ^ {(3 ^ 2)} = 4 ^ {9} = 262144\$.
Because \$4 ^ {(3 ^ 1)} = 4 ^ {3} = 64\$.
Because \$5 ^ {(3 ^ 2)} = 5 ^ {9} = 1953125\$.
Rules:
This is code golf, so the answer with the fewest bytes wins.
If your language has limits on integer size (ex. \$2^{32}-1\$) n will be small enough that the sum will fit in the integer.
Input can be any reasonable form (stdin, file, command line parameter, integer, string, etc).
Output can be any reasonable form (stdout, file, graphical user element that displays the number, etc).
Saw on code wars.
number
s. Do you mean positive integers exclusively? That is I feel how it was interpreted. \$\endgroup\$ – Jonathan Frech Jul 9 '18 at 17:30[999999,213412499,34532599,4125159,53539,54256439,353259,4314319,5325329,1242149,142219,1243219,14149,1242149,124419,999999999]
is valid and the result should be1
If so, this needs to be made clearer in the question as you have upvoted answers that do not solve this (hint - move themod
inside the loop). Perhaps add some examples that make this clear. \$\endgroup\$ – Neil Slater Jul 11 '18 at 9:379
. The digit reduction scheme necessary to implement this is a lot more interesting than the actual answers this problem has garnered. \$\endgroup\$ – Neil Slater Jul 11 '18 at 10:01