Skip to content

Commit 489fc5a

Browse files
committed
Optimize Euclidean distance (re)computuation in 2025 day 8
1 parent 8702586 commit 489fc5a

File tree

1 file changed

+3
-2
lines changed
  • src/main/scala/eu/sim642/adventofcode2025

1 file changed

+3
-2
lines changed

src/main/scala/eu/sim642/adventofcode2025/Day8.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ object Day8 {
2020
// faster than combinations(2)
2121
(p1, i) <- junctionBoxes.iterator.zipWithIndex
2222
p2 <- junctionBoxes.view.slice(i + 1, junctionBoxes.size).iterator
23-
} yield (p1, p2))
23+
} yield (p1, p2) -> (p1 euclideanDistance p2))
2424
.toSeq
25-
.sortBy(_ euclideanDistance _)
25+
.sortBy(_._2)
26+
.map(_._1)
2627
}
2728

2829
class UnionFind[A](val reprs: Map[A, A]) {

0 commit comments

Comments
 (0)