1
0
Fork 0

solve 2022 day 2 part 2

This commit is contained in:
Sloane Perrault 2022-12-02 07:42:52 -05:00
parent 49c7f66b3a
commit 2cd9633fe0
3 changed files with 26 additions and 0 deletions

View file

@ -26,6 +26,7 @@ source-repository head
library
exposed-modules:
Aoc.Day1
Aoc.Day2
other-modules:
Paths_aoc
hs-source-dirs:

View file

@ -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

23
2022/src/Aoc/Day2.hs Normal file
View file

@ -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