Skip to content

Instantly share code, notes, and snippets.

@askl56
Created December 13, 2015 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save askl56/a3ba4a573bc176fcb42a to your computer and use it in GitHub Desktop.
Save askl56/a3ba4a573bc176fcb42a to your computer and use it in GitHub Desktop.
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