Commit 29632086 authored by Neil Smith's avatar Neil Smith
Browse files

Fixing overlong lines

parent a3175189
......@@ -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))
......
......@@ -56,7 +56,9 @@ ruleB seats here thisSeat
where nOccs = M.size $ occupiedInSight seats here
neighbours (r, c) = S.delete (r, c) $ S.fromList [(r + dr, c + dc) | dr <- [-1, 0, 1], dc <- [-1, 0, 1]]
neighbours (r, c) = S.delete (r, c)
$ S.fromList [ (r + dr, c + dc)
| dr <- [-1, 0, 1], dc <- [-1, 0, 1]]
neighbourhood seats here = M.restrictKeys seats (neighbours here)
occupiedNeighbours seats here = M.filter (== Occupied) $ neighbourhood seats here
......@@ -75,15 +77,18 @@ onSightLine (r0, c0) UpRight (r, c) = ((r - r0) < 0) && ((r - r0) == (c0 - c))
manhattan (r1, c1) (r2, c2) = abs (r1 - r2) + abs (c1 - c2)
closestInDirection seats here direction = take 1 sortedSeats
-- where seatsInDirection = M.keys $ M.filterWithKey (\o _ -> onSightLine here direction o) seats
where seatsInDirection = filter (onSightLine here direction) $ M.keys seats
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]]
occupiedInSight :: Seats -> Position -> Seats
occupiedInSight seats here = M.filter (== Occupied) $ M.restrictKeys seats $ closestInSight seats here
occupiedInSight seats here = M.filter (== Occupied)
$ M.restrictKeys seats
$ closestInSight seats here
readGrid :: String -> (Seats, Position)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment