From 481fb8d5d2c4c574a210097d7b441a2d925f7f76 Mon Sep 17 00:00:00 2001 From: Jack Kinsey Date: Mon, 3 Dec 2018 11:45:24 -0500 Subject: [PATCH] Day 3: Extract unoverlap into its own function --- day03/fabric.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/day03/fabric.hs b/day03/fabric.hs index 7921588..6d75042 100644 --- a/day03/fabric.hs +++ b/day03/fabric.hs @@ -6,7 +6,7 @@ main = do 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) @@ -24,6 +24,12 @@ claimOverlap = foldl go M.empty . map claimedAreas 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]] -- 2.38.5