module Days.Day02 where

import AOCUtil
import Data.List

runA :: IO ()
runA = interactF "data/day02.txt" (show . solve . lines)

runB :: IO ()
runB = interactF "data/day02.txt" (show . sum . map (scoreB . words) . lines)

solve :: [String] -> Int
solve = sum . map (score . words)

score :: [String] -> Int
score [a, b] = myScore b + winScore a b
score _ = undefined

-- data Symbol = Rock | Paper | Scissor

-- readSymbol :: String -> Symbol
-- readSymbol "A" = Rock
-- readSymbol "X" = Rock
-- readSymbol "B" = Paper
-- readSymbol "Y" = Paper
-- readSymbol "C" = Scissor
-- readSymbol "Z" = Scissor
-- readSymbol _ = undefined

scoreB :: [String] -> Int
scoreB [a, b] = myScore (choose a b) + winScore a (choose a b)
scoreB _ = undefined

myScore :: String -> Int
myScore "X" = 1
myScore "Y" = 2
myScore "Z" = 3

winScore :: String -> String -> Int
winScore "A" "Y" = 6
winScore "B" "Z" = 6
winScore "C" "X" = 6
winScore "A" "X" = 3
winScore "B" "Y" = 3
winScore "C" "Z" = 3
winScore _ _ = 0

choose :: String -> String -> String
choose "A" "X" = "Z"
choose "A" "Y" = "X"
choose "A" "Z" = "Y"
choose "B" "X" = "X"
choose "B" "Y" = "Y"
choose "B" "Z" = "Z"
choose "C" "X" = "Y"
choose "C" "Y" = "Z"
choose "C" "Z" = "X"
