From cf8aed7e1a4d5c27914425aacaea387a2ed63b48 Mon Sep 17 00:00:00 2001 From: Eric Mertens Date: Sun, 17 Dec 2023 22:36:43 -0800 Subject: [PATCH] foldM --- solutions/src/2023/18.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/solutions/src/2023/18.hs b/solutions/src/2023/18.hs index 63c9e07..15513f4 100644 --- a/solutions/src/2023/18.hs +++ b/solutions/src/2023/18.hs @@ -35,6 +35,7 @@ module Main (main) where import Advent (format, stageTH) import Advent.Box (coverBoxes, intersectBox, size, subtractBox, Box(Pt, Dim), Box') import Advent.Coord (east, north, origin, scaleCoord, south, west, Coord(..)) +import Control.Monad (foldM) import Advent.Search (bfs) import Data.Maybe (isJust) import Numeric (readHex) @@ -62,7 +63,7 @@ solve input = sum (map size ditches) + sum (map size reachable) ditches = makePath origin input everything = coverBoxes ditches - noDitch = foldl (\remain next -> concatMap (subtractBox next) remain) [everything] ditches + noDitch = foldM (flip subtractBox) everything ditches neighbors region = [x | x <- noDitch, touch x region] reachable = drop 1 (bfs neighbors (Dim 1 2 (Dim 1 2 Pt)))