aoc2022/2-b.hs

39 lines
830 B
Haskell

{-# OPTIONS_GHC -Wno-incomplete-patterns #-}
scoreLose = 0
scoreDraw = 3
scoreWin = 6
getMatchScore 'X' = scoreLose
getMatchScore 'Y' = scoreDraw
getMatchScore 'Z' = scoreWin
resolveOptionScore 'X' = 1
resolveOptionScore 'Y' = 2
resolveOptionScore 'Z' = 3
getWinningChoice 'A' = 'Y'
getWinningChoice 'B' = 'Z'
getWinningChoice 'C' = 'X'
getLosingChoice 'A' = 'Z'
getLosingChoice 'B' = 'X'
getLosingChoice 'C' = 'Y'
getDrawChoice 'A' = 'X'
getDrawChoice 'B' = 'Y'
getDrawChoice 'C' = 'Z'
getCorrectChoice 'X' = getLosingChoice
getCorrectChoice 'Y' = getDrawChoice
getCorrectChoice 'Z' = getWinningChoice
getScore a b =
resolveOptionScore correctChoice + getMatchScore b
where correctChoice = getCorrectChoice b a
main = interact $
show
. sum
. map ((\l -> getScore (l !! 0 !! 0) (l !! 1 !! 0)) . words)
. lines