This commit is contained in:
qvalentin 2022-12-10 18:14:23 +01:00
parent b1f6fc6ffc
commit 29efc1f0e8
Signed by: qvalentin
GPG Key ID: C979FA1EAFCABF1C
3 changed files with 2585 additions and 0 deletions

2500
input.txt Normal file

File diff suppressed because it is too large Load Diff

41
two.hs Normal file
View File

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

44
two2.hs Normal file
View File

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