aoc

advent of code
git clone git://source.orangerot.dev:/aoc.git
Log | Files | Refs

Main.hs (543B)


      1 import Data.List.Split (splitOn)
      2 
      3 getGame :: String -> String
      4 getGame s = tail $ dropWhile (/= ':') s
      5 
      6 splitGame :: String -> [[String]]
      7 splitGame s = map (\x -> filter (/= "") (splitOn [' '] x)) (splitOn ['|'] s)
      8 
      9 calcPoints :: [String] -> Int
     10 calcPoints w = round $ 2^^(length w - 1)
     11 
     12 main :: IO ()
     13 main = do
     14   inputLines <- lines <$> getContents
     15   let games = map (\x -> splitGame (getGame x)) inputLines
     16   let wins = map (\[w, cards] -> filter (\card -> elem card w) cards) games 
     17   let points = map calcPoints wins
     18 
     19   print (sum points)
     20