File tree Expand file tree Collapse file tree 1 file changed +3
-3
lines changed
src/main/scala/eu/sim642/adventofcode2025 Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Original file line number Diff line number Diff line change @@ -7,9 +7,9 @@ import eu.sim642.adventofcodelib.pos.Pos3
77object Day8 {
88
99 extension (pos : Pos3 ) {
10- infix def euclideanDistance (that : Pos3 ): Double = {
10+ infix def euclideanDistanceSqr (that : Pos3 ): Long = {
1111 val d = that - pos
12- math.sqrt( d.x.toDouble * d.x + d.y.toDouble * d.y + d.z.toDouble * d.z)
12+ d.x.toLong * d.x + d.y.toLong * d.y + d.z.toLong * d.z
1313 }
1414 }
1515
@@ -19,7 +19,7 @@ object Day8 {
1919 // faster than combinations(2)
2020 (p1, i) <- junctionBoxes.iterator.zipWithIndex
2121 p2 <- junctionBoxes.view.slice(i + 1 , junctionBoxes.size).iterator
22- } yield (p1, p2) -> (p1 euclideanDistance p2))
22+ } yield (p1, p2) -> (p1 euclideanDistanceSqr p2)) // no need to sqrt distance just for sorting
2323 .toSeq
2424 .sortBy(_._2)
2525 .map(_._1)
You can’t perform that action at this time.
0 commit comments