From: Neil Smith Date: Sun, 15 Dec 2024 21:35:41 +0000 (+0000) Subject: Tidying X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=27c6b0f804b2f1132e51c5a3a5e5cd41dd5b78eb;p=advent-of-code-24.git Tidying --- diff --git a/advent15/Main.hs b/advent15/Main.hs index 67dcadc..e4548ef 100644 --- a/advent15/Main.hs +++ b/advent15/Main.hs @@ -1,8 +1,7 @@ --- Writeup at https://work.njae.me.uk/2024/12/12/advent-of-code-2024-day-12/ +-- Writeup at https://work.njae.me.uk/2024/12/15/advent-of-code-2024-day-15/ import AoC import Linear --- import qualified Data.Set as S import qualified Data.Set as S import Data.List (foldl', nub) import Data.Maybe @@ -13,15 +12,12 @@ data World = World { walls :: Items, boxes :: Items, robot :: Position } deriving (Show, Eq, Ord) type Move = (Position, Position) -- move a box from here to there - pattern U, D, L, R :: Position pattern U = V2 (-1) 0 pattern D = V2 1 0 pattern L = V2 0 (-1) pattern R = V2 0 1 - - main :: IO () main = do dataFileName <- getDataFileName @@ -30,19 +26,17 @@ main = let commands = mkCommands text -- print world -- print commands - putStrLn $ showWorld world - let bigWorld = enlarge world - putStrLn $ showBigWorld bigWorld - let world' = foldl' doBigCommand bigWorld commands - putStrLn $ showBigWorld world' - print $ gps world' + -- putStrLn $ showWorld world + -- let bigWorld = enlarge world + -- putStrLn $ showBigWorld bigWorld + -- let world' = foldl' doBigCommand bigWorld commands + -- putStrLn $ showBigWorld world' -- print $ gps world' print $ part1 world commands print $ part2 world commands part1 :: World -> [Position] -> Int part1 world commands = gps $ foldl' doCommand world commands --- part1 regions = sum $ fmap fenceCost $ distinctSets regions part2 world commands = gps $ foldl' doBigCommand bigWorld commands where bigWorld = enlarge world @@ -66,7 +60,6 @@ moveBoxes world dir box return boxedWorld { boxes = boxes'} shift bs = S.insert there $ S.delete box bs - gps :: World -> Int gps World { .. } = sum score where rMax = S.findMax $ S.map (\(V2 r _) -> r) walls @@ -90,7 +83,7 @@ doBigCommand world dir let boxes' = (S.fromList tos) `S.union` (world.boxes `S.difference` (S.fromList froms)) let world' = world { boxes = boxes' } return world' { robot = there } - + moveBigBoxes :: World -> Position -> Position -> Maybe [Move] moveBigBoxes world dir box