summaryrefslogtreecommitdiff
path: root/2023/day04/Main.hs
blob: 9bf100b965b96d6d687591a6076833d8b684476a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import Data.List.Split (splitOn)

getGame :: String -> String
getGame s = tail $ dropWhile (/= ':') s

splitGame :: String -> [[String]]
splitGame s = map (\x -> filter (/= "") (splitOn [' '] x)) (splitOn ['|'] s)

calcPoints :: [String] -> Int
calcPoints w = round $ 2^^(length w - 1)

main :: IO ()
main = do
  inputLines <- lines <$> getContents
  let games = map (\x -> splitGame (getGame x)) inputLines
  let wins = map (\[w, cards] -> filter (\card -> elem card w) cards) games 
  let points = map calcPoints wins

  print (sum points)