projects
/
advent-of-code-20.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Done day 12
[advent-of-code-20.git]
/
advent11
/
src
/
advent11naive.hs
diff --git
a/advent11/src/advent11naive.hs
b/advent11/src/advent11naive.hs
index ac6d260f1ba2f2532bc5ca34334e3767f23443c5..4c55edf0cadb73414259ecbcf4a1cd4e624921d1 100644
(file)
--- a/
advent11/src/advent11naive.hs
+++ b/
advent11/src/advent11naive.hs
@@
-56,7
+56,9
@@
ruleB seats here thisSeat
where nOccs = M.size $ occupiedInSight seats here
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
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
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)
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 -> 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)
readGrid :: String -> (Seats, Position)