From 53c645eff9e9c27d5f93a7a77fa1168c30452638 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Sun, 15 Dec 2024 22:31:16 +0000 Subject: [PATCH] More tidying --- advent15/Main.hs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/advent15/Main.hs b/advent15/Main.hs index e4548ef..211a978 100644 --- a/advent15/Main.hs +++ b/advent15/Main.hs @@ -77,19 +77,18 @@ doBigCommand world dir | otherwise = world { robot = there } where there = world.robot ^+^ dir movedBox = bigBoxActual world.boxes there - rWorld = do boxMoves <- moveBigBoxes world dir movedBox - let froms = fmap fst boxMoves - let tos = fmap snd boxMoves - let boxes' = (S.fromList tos) `S.union` (world.boxes `S.difference` (S.fromList froms)) - let world' = world { boxes = boxes' } - return world' { robot = there } - + rWorld = + do boxMoves <- moveBigBoxes world dir movedBox + let froms = S.fromList $ fmap fst boxMoves + let tos = S.fromList $ fmap snd boxMoves + let boxes' = S.union tos (world.boxes `S.difference` froms) + return world { boxes = boxes', robot = there } moveBigBoxes :: World -> Position -> Position -> Maybe [Move] moveBigBoxes world dir box | any (\t -> t `S.member` world.walls) there = Nothing | any (\t -> t `isBigBox` world.boxes) there = allMoves - | otherwise = Just $ [ thisMove ] + | otherwise = Just [ thisMove ] where there = case dir of U -> [box ^+^ U, box ^+^ R ^+^ U] D -> [box ^+^ D, box ^+^ R ^+^ D] @@ -97,7 +96,8 @@ moveBigBoxes world dir box R -> [box ^+^ R ^+^ R] _ -> [] thisMove = (box, box ^+^ dir) - allMoves = do let there' = nub $ fmap (bigBoxActual world.boxes) $ filter (\t -> t `isBigBox` world.boxes) there + allMoves = do let there' = nub $ fmap (bigBoxActual world.boxes) + $ filter (\t -> t `isBigBox` world.boxes) there moves <- traverse (moveBigBoxes world dir) there' let moves' = concat moves return $ thisMove : moves' -- 2.34.1