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)