X-Git-Url: https://git.njae.me.uk/?p=advent-of-code-20.git;a=blobdiff_plain;f=advent11%2Fsrc%2Fadvent11.hs;h=6fdfd6262c2c4f8414551b63d0f22a3496a9a558;hp=b56dc3df12a75893d6dd9db4a188a8ad23aab8fd;hb=29632086e7a87829401fb09a8ddd809d79502347;hpb=a3175189f99c76ed782189826efdde2fbadfd708 diff --git a/advent11/src/advent11.hs b/advent11/src/advent11.hs index b56dc3d..6fdfd62 100644 --- a/advent11/src/advent11.hs +++ b/advent11/src/advent11.hs @@ -85,7 +85,8 @@ neighbourhood seats here = S.intersection (M.keysSet seats) (neighbours here) allNeighbourhoods :: Seats -> Neighbourhood allNeighbourhoods seats = M.mapWithKey (\h _ -> neighbourhood seats h) seats -occupiedNeighbours seats nbrs here = M.filter (== Occupied) $ M.restrictKeys seats (nbrs!here) +occupiedNeighbours seats nbrs here = M.filter (== Occupied) + $ M.restrictKeys seats (nbrs!here) onSightLine :: Position -> Direction -> Position -> Bool @@ -106,15 +107,12 @@ closestInDirection seats here direction = take 1 sortedSeats sortedSeats = sortOn (manhattan here) seatsInDirection closestInSight :: Seats -> Position -> (S.Set Position) -closestInSight seats here = S.fromList $ concatMap (closestInDirection seats here) [d | d <- [Up .. UpLeft]] +closestInSight seats here = S.fromList + $ concatMap (closestInDirection seats here) [d | d <- [Up .. UpLeft]] allSightNeighbourhoods :: Seats -> Neighbourhood allSightNeighbourhoods seats = M.mapWithKey (\h _ -> closestInSight seats h) seats --- occupiedInSight :: Seats -> Position -> Seats --- occupiedInSight seats here = M.filter (== Occupied) $ M.restrictKeys seats $ closestInSight seats here - - readGrid :: String -> (Seats, Position) readGrid input = (seats, (maxR, maxC))