diff --git a/src/main/kotlin/no/rodland/advent_2023/Day09.kt b/src/main/kotlin/no/rodland/advent_2023/Day09.kt index eab605a..7343269 100644 --- a/src/main/kotlin/no/rodland/advent_2023/Day09.kt +++ b/src/main/kotlin/no/rodland/advent_2023/Day09.kt @@ -14,16 +14,14 @@ class Day09(val input: List) : Day>> { } override fun partTwo(): Int { - return parsed.sumOf { it.previous() } + return parsed.map { it.reversed() }.sumOf { it.next() } } private fun List.next(): Int = if (all { it == 0 }) 0 - else last() + diffs().next() + else last() + zipWithNext { a, b -> b - a }.next() - private fun List.previous(): Int = if (all { it == 0 }) 0 - else first() - diffs().previous() - - private fun List.diffs(): List = zipWithNext { a, b -> b - a } +// private fun List.previous(): Int = if (all { it == 0 }) 0 +// else first() - diffs().previous() override fun List.parse(): List> { return map { line ->