Skip to content

Commit

Permalink
foldM
Browse files Browse the repository at this point in the history
  • Loading branch information
glguy committed Dec 18, 2023
1 parent 4c49539 commit cf8aed7
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion solutions/src/2023/18.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)))

Expand Down

0 comments on commit cf8aed7

Please sign in to comment.