solve 2022 day 2 part 2
This commit is contained in:
parent
49c7f66b3a
commit
2cd9633fe0
3 changed files with 26 additions and 0 deletions
|
@ -26,6 +26,7 @@ source-repository head
|
||||||
library
|
library
|
||||||
exposed-modules:
|
exposed-modules:
|
||||||
Aoc.Day1
|
Aoc.Day1
|
||||||
|
Aoc.Day2
|
||||||
other-modules:
|
other-modules:
|
||||||
Paths_aoc
|
Paths_aoc
|
||||||
hs-source-dirs:
|
hs-source-dirs:
|
||||||
|
|
|
@ -3,6 +3,7 @@ module Main (main) where
|
||||||
|
|
||||||
import System.Environment (getArgs)
|
import System.Environment (getArgs)
|
||||||
import qualified Aoc.Day1
|
import qualified Aoc.Day1
|
||||||
|
import qualified Aoc.Day2
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
|
@ -13,6 +14,7 @@ main = do
|
||||||
contents <- readFile ("input/" ++ (show day) ++ ".txt")
|
contents <- readFile ("input/" ++ (show day) ++ ".txt")
|
||||||
|
|
||||||
let f = case day of 1 -> Aoc.Day1.solve
|
let f = case day of 1 -> Aoc.Day1.solve
|
||||||
|
2 -> Aoc.Day2.solve
|
||||||
_ -> error "unknown day"
|
_ -> error "unknown day"
|
||||||
|
|
||||||
putStrLn $ show $ f part contents
|
putStrLn $ show $ f part contents
|
||||||
|
|
23
2022/src/Aoc/Day2.hs
Normal file
23
2022/src/Aoc/Day2.hs
Normal 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
|
Loading…
Reference in a new issue