You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
case (max, (n, d)) => max.max(search(n, dist + d))
182
186
@@ -212,20 +216,23 @@ Next, we define an adjacency graph. Since `connectedJunctions` takes slopes into
212
216
213
217
```scala
214
218
valadjacent:Map[Index, List[(Index, Int)]] =
215
-
maze.junctions.toList.flatMap: p1 =>
216
-
connectedJunctions(p1).flatMap: (p2, d) =>
217
-
valforward= indexOf(p1) -> (indexOf(p2), d)
218
-
valreverse= indexOf(p2) -> (indexOf(p1), d)
219
-
List(forward, reverse)
220
-
.groupMap(_._1)(_._2)
219
+
maze.junctions.toList
220
+
.flatMap: p1 =>
221
+
connectedJunctions(p1).flatMap: (p2, d) =>
222
+
valforward= indexOf(p1) -> (indexOf(p2), d)
223
+
valreverse= indexOf(p2) -> (indexOf(p1), d)
224
+
List(forward, reverse)
225
+
.groupMap(_(0))(_(1))
221
226
```
222
227
223
228
Finally, we perform a depth-first search that is very similar to what we used in Part 1.
224
229
The main differences are that we now use indices of junctions rather than `Point`s representing current position, and we now check adjacent junctions against a BitSet of visited points, which we now track as we search recursively.
0 commit comments