Minor tweaking of Day 5.

This commit is contained in:
Chris Hodges 2025-12-05 06:27:46 +01:00
parent c82509468a
commit f51f87736b

View File

@ -38,7 +38,6 @@ fun main() {
}
fun part2(input: List<String>): Long {
var freshSum = 0L
val ranges = ArrayList<LongRange>()
for (i in input) {
if (i.contains("-")) {
@ -61,13 +60,7 @@ fun main() {
}
}
consolidated.add(LongRange(lastLow, lastHigh))
for (r in consolidated) {
val e = r.last - r.first + 1
// had read that you should sum all of the IDs, then it would have been e * r.first + (e * e + 1) / 2
freshSum += e
}
return freshSum
return consolidated.sumOf { it.last - it.first + 1 }
}
// test if implementation meets criteria from the description, like: