28 lines
774 B
Haskell
28 lines
774 B
Haskell
{-# LANGUAGE LambdaCase #-}
|
|
module Main where
|
|
|
|
import Data.Functor
|
|
import Data.List.Split
|
|
import Data.Map (Map)
|
|
import qualified Data.Map as Map
|
|
|
|
parse :: String -> (Map Int [Int], [[Int]])
|
|
parse s = let [a,b] = splitOn "\n\n" s in
|
|
( foldr (\[x,y] m -> Map.insertWith (++) (read x) ([read y]) m) Map.empty . (splitOn "|" <$>) $ lines a
|
|
, ((read <$>) . splitOn "," <$>) $ lines b)
|
|
|
|
fix1 :: Map Int [Int] -> [Int] -> [Int]
|
|
fix1 _ [ ] = [ ]
|
|
fix1 _ [x] = [x]
|
|
fix1 r (x:y:es) = undefined --TODO
|
|
|
|
solve1 :: Map Int [Int] -> [[Int]] -> Int
|
|
solve1 r l = sum $ l <&> (\a -> let t = length a in a !! (t `div` 2)) . fix1 r
|
|
|
|
solve2 = undefined
|
|
|
|
main :: IO ()
|
|
main = readFile "inputs/5.example" <&> parse >>= \i ->
|
|
print (uncurry solve1 i)
|
|
--print (solve2 i)
|