let layout = claimOverlap claims
let counts = M.fromListWith (+) . map (\v -> (v,1)) . M.elems $ layout
print $ counts M.! (-1)
- print . index . head . filter (\c -> (fst . size $ c)*(snd . size $ c) == M.findWithDefault 0 (index c) counts) $ claims
+ print . index . claimUnoverlapped counts $ claims
data Claim = Claim { index :: Int
, coord :: (Int, Int)
go :: ClaimMap -> [(Int, (Int, Int))] -> ClaimMap
go cmap = foldl mn cmap
+claimUnoverlapped :: M.Map Int Int -> [Claim] -> Claim
+claimUnoverlapped counts = head . filter go
+ where go :: Claim -> Bool
+ go (Claim ind _ (sx, sy)) =
+ (Just (sx*sy)) == counts M.!? ind
+
claimedAreas :: Claim -> [(Int, (Int, Int))]
claimedAreas (Claim ind (cx, cy) (sx, sy)) =
[(ind,(i,j)) | i <- [cx+1..cx+sx], j <- [cy+1..cy+sy]]