Created
December 3, 2022 09:16
-
-
Save evinism/ba9c51636bb9d436faa70f6704b0f64d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import Data.List | |
import qualified Data.Text as T | |
main = do | |
input <- readFile "input.txt" | |
print $ fn input | |
fn :: String -> Int | |
fn input = sum $ fmap scoreline $ lines input | |
scoreline :: String -> Int | |
scoreline (theirs : space : ours : xs) = gamescore theirs ours + scoreindividual ours | |
scoreline _ = undefined | |
gamescore :: Char -> Char -> Int | |
gamescore 'A' 'Y' = 1 | |
gamescore 'B' 'Z' = 3 | |
gamescore 'C' 'X' = 2 | |
gamescore 'A' 'X' = 3 | |
gamescore 'B' 'Y' = 2 | |
gamescore 'C' 'Z' = 1 | |
gamescore 'A' 'Z' = 2 | |
gamescore 'B' 'X' = 1 | |
gamescore 'C' 'Y' = 3 | |
gamescore _ _ = undefined | |
scoreindividual :: Char -> Int | |
scoreindividual 'X' = 0 | |
scoreindividual 'Y' = 3 | |
scoreindividual 'Z' = 6 | |
scoreindividual _ = undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment