day two
This commit is contained in:
parent
b1f6fc6ffc
commit
29efc1f0e8
|
@ -0,0 +1,41 @@
|
|||
|
||||
|
||||
data Rock
|
||||
data Paper
|
||||
data Scissors
|
||||
|
||||
type X = Rock
|
||||
type Y = Paper
|
||||
type Z = Scissors
|
||||
|
||||
type A = Rock
|
||||
type B = Paper
|
||||
type C = Scissors
|
||||
|
||||
data Action = X | Y | Z deriving (Show,Read, Eq)
|
||||
data Enemy = A | B | C deriving (Show,Read, Eq)
|
||||
|
||||
data Game = Game Enemy Action deriving (Show,Read)
|
||||
|
||||
selectedScore :: Action -> Int
|
||||
selectedScore X = 1
|
||||
selectedScore Y = 2
|
||||
selectedScore Z = 3
|
||||
|
||||
resultScore :: Game -> Int
|
||||
resultScore (Game A X) = 3
|
||||
resultScore (Game A Y) = 6
|
||||
resultScore (Game A Z) = 0
|
||||
resultScore (Game B X) = 0
|
||||
resultScore (Game B Y) = 3
|
||||
resultScore (Game B Z) = 6
|
||||
resultScore (Game C X) = 6
|
||||
resultScore (Game C Y) = 0
|
||||
resultScore (Game C Z) = 3
|
||||
|
||||
gameScore :: Game -> Int
|
||||
gameScore (Game enemy action) = (resultScore (Game enemy action)) + selectedScore action
|
||||
|
||||
main = do
|
||||
input <- readFile "input.txt"
|
||||
putStrLn $ show$ sum $ map (gameScore . read . ("Game "<> )) $ lines input
|
|
@ -0,0 +1,44 @@
|
|||
|
||||
|
||||
data Rock
|
||||
data Paper
|
||||
data Scissors
|
||||
|
||||
type X = Rock
|
||||
type Y = Paper
|
||||
type Z = Scissors
|
||||
|
||||
type A = Rock
|
||||
type B = Paper
|
||||
type C = Scissors
|
||||
|
||||
data Action = X | Y | Z deriving (Show,Read, Eq)
|
||||
data Enemy = A | B | C deriving (Show,Read, Eq)
|
||||
|
||||
data Game = Game Enemy Action deriving (Show,Read)
|
||||
|
||||
selectedScore :: Action -> Int
|
||||
--selectedScore X = 1
|
||||
--selectedScore Y = 2
|
||||
--selectedScore Z = 3
|
||||
selectedScore X = 0
|
||||
selectedScore Y = 3
|
||||
selectedScore Z = 6
|
||||
|
||||
resultScore :: Game -> Int
|
||||
resultScore (Game A X) = 3
|
||||
resultScore (Game A Y) = 1
|
||||
resultScore (Game A Z) = 2
|
||||
resultScore (Game B X) = 1
|
||||
resultScore (Game B Y) = 2
|
||||
resultScore (Game B Z) = 3
|
||||
resultScore (Game C X) = 2
|
||||
resultScore (Game C Y) = 3
|
||||
resultScore (Game C Z) = 1
|
||||
|
||||
gameScore :: Game -> Int
|
||||
gameScore (Game enemy action) = (resultScore (Game enemy action)) + selectedScore action
|
||||
|
||||
main = do
|
||||
input <- readFile "input.txt"
|
||||
putStrLn $ show$ sum $ map (gameScore . read . ("Game "<> )) $ lines input
|
Loading…
Reference in New Issue