Started on 5
This commit is contained in:
parent
d67ee1fac7
commit
1a10659e03
@ -62,6 +62,7 @@ executable 5
|
||||
-- other-extensions:
|
||||
build-depends: base ^>=4.18.2.1
|
||||
, split
|
||||
, containers
|
||||
hs-source-dirs: app
|
||||
default-language: GHC2021
|
||||
executable 6
|
||||
|
22
app/5.hs
22
app/5.hs
@ -2,14 +2,26 @@
|
||||
module Main where
|
||||
|
||||
import Data.Functor
|
||||
import Data.List.Split
|
||||
import Data.Map (Map)
|
||||
import qualified Data.Map as Map
|
||||
|
||||
parse = undefined
|
||||
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)
|
||||
|
||||
solve1 = undefined
|
||||
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" <&> parse >>= \i ->
|
||||
print (solve1 i) >>
|
||||
print (solve2 i)
|
||||
main = readFile "inputs/5.example" <&> parse >>= \i ->
|
||||
print (uncurry solve1 i)
|
||||
--print (solve2 i)
|
||||
|
Loading…
Reference in New Issue
Block a user