-
-
Save himself65/cbffe7340eb9e9967ee20581c202c601 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
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