Done day 20
[advent-of-code-18.git] / src / advent03 / advent03.hs
index cf7f9456b4aadc0ed75c6fb0d006e7673cec1ee1..48449da4225af0bb35b1d0e462ec08bb0d686bff 100644 (file)
@@ -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 =