-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday2-2.hs
More file actions
33 lines (30 loc) · 833 Bytes
/
day2-2.hs
File metadata and controls
33 lines (30 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import System.IO
import Control.Monad
import Data.List
main = do
let list = []
handle <- openFile "day2_input" ReadMode
contents <- hGetContents handle
let games = lines contents
let results = map words games
let score = map resultscore results
let totalscore = sum score
print totalscore
hClose handle
symbolscore :: String -> String -> Int
symbolscore "A" "X" = 3
symbolscore "A" "Y" = 1
symbolscore "A" "Z" = 2
symbolscore "B" "X" = 1
symbolscore "B" "Y" = 2
symbolscore "B" "Z" = 3
symbolscore "C" "X" = 2
symbolscore "C" "Y" = 3
symbolscore "C" "Z" = 1
symbolscore _ _ = 0
resultscore :: [String] -> Int
resultscore [a,b] = case b of
("X") -> 0 + symbolscore a b
("Y") -> 3 + symbolscore a b
("Z") -> 6 + symbolscore a b
(_) -> 0