# Pastebin dUC7zGuy module Day2Gqplox where data Shape = Rock | Paper | Scissors deriving (Show, Ord, Eq, Enum) data Outcome = Win | Draw | Lose deriving (Show, Ord, Eq, Enum) shapeScore :: Shape -> Int shapeScore = succ . fromEnum score :: Shape -> Outcome -> Int score opp Win = 6 + (shapeScore . wrappedSucc) opp score opp Draw = 3 + shapeScore opp score opp Lose = 0 + (shapeScore . wrappedPred) opp wrappedSucc :: Shape -> Shape wrappedSucc Scissors = Rock wrappedSucc s = succ s wrappedPred :: Shape -> Shape wrappedPred = wrappedSucc . wrappedSucc parseShape :: Char -> Shape parseShape 'A' = Rock parseShape 'B' = Paper parseShape 'C' = Scissors parseOutcome :: Char -> Outcome parseOutcome 'X' = Lose parseOutcome 'Y' = Draw parseOutcome 'Z' = Win solve :: [(Shape, Outcome)] -> Int solve = sum . map (uncurry score) parse :: String -> (Shape, Outcome) parse str = case str of [s, ' ', o] -> (parseShape s, parseOutcome o) _ -> error "errors are bad" part2 :: IO Int part2 = solve . map parse . lines <$> readFile "input/day2"