diff --git a/src/main/kotlin/no/rodland/advent_2024/Day05.kt b/src/main/kotlin/no/rodland/advent_2024/Day05.kt index 5618a7bc..aa4813c6 100644 --- a/src/main/kotlin/no/rodland/advent_2024/Day05.kt +++ b/src/main/kotlin/no/rodland/advent_2024/Day05.kt @@ -26,10 +26,13 @@ class Day05(val input: List) : Day>, Li } override fun partTwo(): Int { - return pages - .filterNot { it.valid() } - .map { it.sort() } - .sumOf { it[it.size / 2] } + // only sorting once + return pages.map { it.sort() }.zip(pages).filter { it.first != it.second }.map { it.first }.sumOf { it[it.size / 2] } + // more readable + // return pages + // .filterNot { it.valid() } + // .map { it.sort() } + // .sumOf { it[it.size / 2] } } private fun List.valid(): Boolean = sort() == this