Skip to content

Commit

Permalink
Replace deprecated calls
Browse files Browse the repository at this point in the history
  • Loading branch information
pkoziol committed Dec 14, 2023
1 parent 52494fe commit 04452e4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ data class WastelandNode(val id: String) {
}

fun parseWastelandMap(lines: List<String>): WastelandMap {
val instructions = lines.first
val instructions = lines.first()
val regex = Regex("(?<start>[A-Z0-9]+) = \\((?<left>[A-Z0-9]+), (?<right>[A-Z0-9]+)\\)")

val nodes = lines
Expand Down
12 changes: 6 additions & 6 deletions src/main/kotlin/biz/koziolek/adventofcode/year2023/day09/day9.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,28 @@ fun parseOasisReport(lines: Iterable<String>): OasisReport =
.let { OasisReport(it) }

fun predictNextValue(history: List<Int>): Int =
extrapolateHistory(history).first.last
extrapolateHistory(history).first().last()

fun predictPreviousValue(history: List<Int>): Int =
extrapolateHistoryBackwards(history).first.first
extrapolateHistoryBackwards(history).first().first()

internal fun extrapolateHistory(history: List<Int>): List<List<Int>> {
val reduced = reduceHistory(history)
val lastRowExtended = reduced.last + 0
val lastRowExtended = reduced.last() + 0
return reduced
.dropLast(1)
.foldRight(listOf(lastRowExtended)) { ints, acc ->
val newRow = ints + (ints.last + acc.first.last)
val newRow = ints + (ints.last() + acc.first().last())
listOf(newRow) + acc
}
}
internal fun extrapolateHistoryBackwards(history: List<Int>): List<List<Int>> {
val reduced = reduceHistory(history)
val lastRowExtended = listOf(0) + reduced.last
val lastRowExtended = listOf(0) + reduced.last()
return reduced
.dropLast(1)
.foldRight(listOf(lastRowExtended)) { ints, acc ->
val newRow = listOf(ints.first - acc.first.first) + ints
val newRow = listOf(ints.first() - acc.first().first()) + ints
listOf(newRow) + acc
}
}
Expand Down

0 comments on commit 04452e4

Please sign in to comment.