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\$2**3 % 10 == 2**7 % 10 == 2**11 % 10
. Other last digits have different patterns. This knowledge is necessary to complete the puzzle and cope with arrays of numbers that would otherwise be too large to process. As far as I can tell, none of the answers here actually cope with the original problem as posed on Code Wars. \$\endgroup\$[999999,213412499,34532599,4125159,53539,54256439,353259,4314319,5325329,1242149,142219,1243219,14149,1242149,124419,999999999]
is straightforward, base ends with 9, so last digit is 9 when first exponent is odd, 1 when exponent is even. I would really like a codegolf that limits inputs to the available integer range, and not the full exponential. \$\endgroup\$