Skip to content

Instantly share code, notes, and snippets.

@himself65
Created November 22, 2019 00:05
Show Gist options
  • Save himself65/cbffe7340eb9e9967ee20581c202c601 to your computer and use it in GitHub Desktop.
Save himself65/cbffe7340eb9e9967ee20581c202c601 to your computer and use it in GitHub Desktop.
lastDigit :: [Integer] -> Integer
lastDigit [] = 1
lastDigit [x] = x `rem` 10
lastDigit (x:xs) = (x `rem` 10) ^ y `rem` 10
where
y =
case xs of
[k] -> (k - 1) `rem` 4 + 1
otherwise -> foldr1 f xs
f a 0 = 1
f a b =
let a' =
if a <= 1
then a
else (a + 2) `rem` 4 + 2
in case a' of
2 ->
if b = 1
then 2
else 4
3 ->
if b `rem` 2 = 0
then 5
else 3
otherwise -> a'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment