Minor tweaking of Day 5.
This commit is contained in:
parent
c82509468a
commit
f51f87736b
@ -38,7 +38,6 @@ fun main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun part2(input: List<String>): Long {
|
fun part2(input: List<String>): Long {
|
||||||
var freshSum = 0L
|
|
||||||
val ranges = ArrayList<LongRange>()
|
val ranges = ArrayList<LongRange>()
|
||||||
for (i in input) {
|
for (i in input) {
|
||||||
if (i.contains("-")) {
|
if (i.contains("-")) {
|
||||||
@ -61,13 +60,7 @@ fun main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
consolidated.add(LongRange(lastLow, lastHigh))
|
consolidated.add(LongRange(lastLow, lastHigh))
|
||||||
|
return consolidated.sumOf { it.last - it.first + 1 }
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// test if implementation meets criteria from the description, like:
|
// test if implementation meets criteria from the description, like:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user