type Player1 = Choice
type Player2 = Choice
do
content <- input 2
let run = Aoc.run content
run (pure 14264) (strategy one)
run (pure 12382) (strategy two)
where
one = parse (\x -> (snd x, uncurry (flip outcome) x)) parseChoice parseChoice
two = parse (\x -> first (decide (snd x)) x) parseChoice parseOutcome
sum . map (uncurry score) . a
data Choice = Rock | Paper | Scissor
data Outcome = Loss | Draw | Win
Loss
Scissor
beats a = pred a
Rock
loses a = succ a
(+1) . fromEnum
(*3) . fromEnum
choiceScore a + outcomeScore b
Rock
parseChoice 'X' = Rock
parseChoice 'B' = Paper
parseChoice 'Y' = Paper
parseChoice 'C' = Scissor
parseChoice 'Z' = Scissor
parseChoice _ = error "malformed input"
-- for part2
Loss
parseOutcome 'Y' = Draw
parseOutcome 'Z' = Win
parseOutcome _ = error "malformed input"
bimap a b (x, y)
map (a . parseTurn b c) . lines
loses a
decide Draw a = a
decide Loss a = beats a