X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=src%2Fadvent03%2Fadvent03.hs;h=48449da4225af0bb35b1d0e462ec08bb0d686bff;hb=39f66aef92beb2f8b7bd96b2e03d54a98187cfab;hp=cf7f9456b4aadc0ed75c6fb0d006e7673cec1ee1;hpb=f27f9c8f46cf9198df78dd1d0c536831ca49e885;p=advent-of-code-18.git diff --git a/src/advent03/advent03.hs b/src/advent03/advent03.hs index cf7f945..48449da 100644 --- a/src/advent03/advent03.hs +++ b/src/advent03/advent03.hs @@ -17,7 +17,7 @@ import qualified Data.Map.Strict as M -- import Data.Map.Strict ((!)) -type Position = (Int, Int) +type Position = (Int, Int) -- row, column data Claim = Claim { claimId :: Int, claimTopLeft :: Position, claimWidth :: Int, claimHeight :: Int } deriving (Show, Eq) type Fabric = M.Map Position Int @@ -39,10 +39,10 @@ part2 fabric claims = claimId $ head $ filter noOverlap' claims claimedSquares :: Claim -> [Position] -claimedSquares claim = [(r, c) | r <- [l .. (l + w - 1)] - , c <- [t .. (t + h - 1)] +claimedSquares claim = [(r, c) | r <- [r0 .. (r0 + h - 1)] + , c <- [c0 .. (c0 + w - 1)] ] - where (t, l) = claimTopLeft claim + where (r0, c0) = claimTopLeft claim h = claimHeight claim w = claimWidth claim @@ -86,7 +86,7 @@ leftTopP = (,) <$> integer <* commaP <*> integer widthHeightP = (,) <$> integer <* exP <*> integer claimP = claimify <$> idP <* atP <*> leftTopP <* colonP <*> widthHeightP - where claimify cid lt (w, h) = Claim { claimId = cid, claimTopLeft = swap lt, claimWidth = w, claimHeight = h } + where claimify cid cr (w, h) = Claim { claimId = cid, claimTopLeft = swap cr, claimWidth = w, claimHeight = h } successfulParse :: Text -> [Claim] successfulParse input =