Skip to content

Instantly share code, notes, and snippets.

@evinism
Created December 3, 2022 09:16
Show Gist options
  • Save evinism/ba9c51636bb9d436faa70f6704b0f64d to your computer and use it in GitHub Desktop.
Save evinism/ba9c51636bb9d436faa70f6704b0f64d to your computer and use it in GitHub Desktop.
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