# Pastebin jLoy9DIF 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 -> Maybe Shape parseShape 'A' = Just Rock parseShape 'B' = Just Paper parseShape 'C' = Just Scissors parseShape _ = Nothing parseOutcome :: Char -> Maybe Outcome parseOutcome 'X' = Just Lose parseOutcome 'Y' = Just Draw parseOutcome 'Z' = Just Win parseOutcome _ = Nothing solve :: [(Shape, Outcome)] -> Int solve = sum . map (uncurry score) parse :: String -> Maybe (Shape, Outcome) parse str = case str of [s, ' ', o] -> (,) <$> parseShape s <*> parseOutcome o _ -> Nothing part2 :: IO Int part2 = maybe 0 solve . traverse parse . lines <$> readFile "input/day2"