-
-
Save askl56/a3ba4a573bc176fcb42a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LAST_DIGITS = [ | |
[0], | |
[1], | |
[2, 4, 8, 6], | |
[3, 9, 7, 1], | |
[4, 6], | |
[5], | |
[6], | |
[7, 9, 3, 1], | |
[8, 4, 2, 6], | |
[9, 1] | |
] | |
def last_digit(n1, n2) | |
return 1 if n2 == 0 | |
digits = LAST_DIGITS[n1 % 10] | |
digits[(n2 - 1) % digits.length] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment