Day 8: Use long for result of part 2. X coords are > 16 bit. That it didn't overflow was pure chance.

This commit is contained in:
Chris Hodges 2025-12-08 07:07:39 +01:00
parent 52af74ecd5
commit 909fb5c7d2

View File

@ -88,7 +88,7 @@ fun main() {
return circuitSizes.sortedDescending().take(3).fold(1L) { acc, l -> acc * l }
}
fun part2(input: List<String>): Int {
fun part2(input: List<String>): Long {
val nodes = input.map { it.splitInts(",").toIntArray() }.toTypedArray()
val distances = createDistances(nodes)
@ -100,11 +100,11 @@ fun main() {
if (union(unionFindParentArray, n1, n2)) {
numCircuits++
if (numCircuits == n) {
return nodes[n1][0] * nodes[n2][0]
return nodes[n1][0].toLong() * nodes[n2][0]
}
}
}
return -1
return -1L
}
// test if implementation meets criteria from the description, like:
@ -115,7 +115,7 @@ fun main() {
val testInputPart2Result = part2(testInput)
println("Part 2 Test: $testInputPart2Result")
check(testInputPart1Result == 40L)
check(testInputPart2Result == 25272)
check(testInputPart2Result == 25272L)
val input = readInput("aoc2025/Day08")
part1(input, 1000).println()