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:
parent
52af74ecd5
commit
909fb5c7d2
@ -88,7 +88,7 @@ fun main() {
|
|||||||
return circuitSizes.sortedDescending().take(3).fold(1L) { acc, l -> acc * l }
|
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 nodes = input.map { it.splitInts(",").toIntArray() }.toTypedArray()
|
||||||
val distances = createDistances(nodes)
|
val distances = createDistances(nodes)
|
||||||
|
|
||||||
@ -100,11 +100,11 @@ fun main() {
|
|||||||
if (union(unionFindParentArray, n1, n2)) {
|
if (union(unionFindParentArray, n1, n2)) {
|
||||||
numCircuits++
|
numCircuits++
|
||||||
if (numCircuits == n) {
|
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:
|
// test if implementation meets criteria from the description, like:
|
||||||
@ -115,7 +115,7 @@ fun main() {
|
|||||||
val testInputPart2Result = part2(testInput)
|
val testInputPart2Result = part2(testInput)
|
||||||
println("Part 2 Test: $testInputPart2Result")
|
println("Part 2 Test: $testInputPart2Result")
|
||||||
check(testInputPart1Result == 40L)
|
check(testInputPart1Result == 40L)
|
||||||
check(testInputPart2Result == 25272)
|
check(testInputPart2Result == 25272L)
|
||||||
|
|
||||||
val input = readInput("aoc2025/Day08")
|
val input = readInput("aoc2025/Day08")
|
||||||
part1(input, 1000).println()
|
part1(input, 1000).println()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user