-- 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
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
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 =