19 lines
482 B
Haskell
19 lines
482 B
Haskell
import Data.List
|
|
|
|
main :: IO ()
|
|
main = do
|
|
input <- map parse . lines <$> readFile "input"
|
|
print $ sum $ map ((`div` 2) . (2 ^) . wins) input
|
|
print $ sum $ map (play input) [0 .. pred $ length input]
|
|
|
|
parse :: String -> [Int]
|
|
parse = map read . delete "|" . drop 2 . words
|
|
|
|
wins :: [Int] -> Int
|
|
wins = length . filter (/= 1) . map length . group . sort
|
|
|
|
play :: [[Int]] -> Int -> Int
|
|
play input n = 1 + sum (map (play input) [n + 1 .. n + w])
|
|
where
|
|
w = wins (input !! n)
|