--- 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
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
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
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
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