diff --git a/2022/aoc.cabal b/2022/aoc.cabal index 41b5d48..3166d85 100644 --- a/2022/aoc.cabal +++ b/2022/aoc.cabal @@ -26,6 +26,7 @@ source-repository head library exposed-modules: Aoc.Day1 + Aoc.Day2 other-modules: Paths_aoc hs-source-dirs: diff --git a/2022/app/Main.hs b/2022/app/Main.hs index 0570781..d6bf0ab 100644 --- a/2022/app/Main.hs +++ b/2022/app/Main.hs @@ -3,6 +3,7 @@ module Main (main) where import System.Environment (getArgs) import qualified Aoc.Day1 +import qualified Aoc.Day2 main :: IO () main = do @@ -13,6 +14,7 @@ main = do contents <- readFile ("input/" ++ (show day) ++ ".txt") let f = case day of 1 -> Aoc.Day1.solve + 2 -> Aoc.Day2.solve _ -> error "unknown day" putStrLn $ show $ f part contents diff --git a/2022/src/Aoc/Day2.hs b/2022/src/Aoc/Day2.hs new file mode 100644 index 0000000..ba86738 --- /dev/null +++ b/2022/src/Aoc/Day2.hs @@ -0,0 +1,23 @@ +module Aoc.Day2 (solve) where + +solve 1 input = sum $ map scoreGame guide + where + guide = map words . lines $ input + + loss = 0 + draw = 3 + win = 6 + + rock = 1 + paper = 2 + scissors = 3 + + scoreGame ["A", "X"] = rock + draw + scoreGame ["A", "Y"] = paper + win + scoreGame ["A", "Z"] = scissors + loss + scoreGame ["B", "X"] = rock + loss + scoreGame ["B", "Y"] = paper + draw + scoreGame ["B", "Z"] = scissors + win + scoreGame ["C", "X"] = rock + win + scoreGame ["C", "Y"] = paper + loss + scoreGame ["C", "Z"] = scissors + draw