3 kyu

Last digit of a huge number

302 of 7,818Bodigrim

Description:

For a given list [x1, x2, x3, ..., xn] compute the last (decimal) digit of x1 ^ (x2 ^ (x3 ^ (... ^ xn))).

E. g., with the input [3, 4, 2], your code should return 1 because 3 ^ (4 ^ 2) = 3 ^ 16 = 43046721.

Beware: powers grow incredibly fast. For example, 9 ^ (9 ^ 9) has more than 369 millions of digits. lastDigit has to deal with such numbers efficiently.

Corner cases: we assume that 0 ^ 0 = 1 and that lastDigit of an empty list equals to 1.

This kata generalizes Last digit of a large number; you may find useful to solve it beforehand.

Algorithms
Mathematics

More By Author:

Check out these other kata created by Bodigrim

Stats:

CreatedMar 30, 2015
PublishedMar 30, 2015
Warriors Trained43400
Total Skips8396
Total Code Submissions164832
Total Times Completed7818
Haskell Completions174
JavaScript Completions1516
Python Completions4555
Go Completions221
Rust Completions302
C# Completions390
C++ Completions528
Swift Completions23
CoffeeScript Completions19
Ruby Completions153
C Completions290
Prolog Completions14
COBOL Completions16
Scala Completions8
Java Completions43
Total Stars1876
% of votes with a positive feedback rating87% of 1025
Total "Very Satisfied" Votes823
Total "Somewhat Satisfied" Votes143
Total "Not Satisfied" Votes59
Ad
Contributors
  • Bodigrim Avatar
  • jhoffner Avatar
  • jcsahnwaldt Avatar
  • TellowKrinkle Avatar
  • isqua Avatar
  • imjasonmiller Avatar
  • kazk Avatar
  • JohanWiltink Avatar
  • B1ts Avatar
  • Voile Avatar
  • Madjosz Avatar
  • Bubbler Avatar
  • arrem Avatar
  • FArekkusu Avatar
  • USM Avatar
  • iNont Avatar
  • metalim Avatar
  • monadius Avatar
  • hobovsky Avatar
  • akar-0 Avatar
  • vpereira01 Avatar
  • KayleighWasTaken Avatar
  • saudiGuy Avatar
Ad