Skip to content

Commit

Permalink
More cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ephemient committed Dec 24, 2022
1 parent 5d4bbb9 commit 91d0716
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions kt/src/commonMain/kotlin/com/github/ephemient/aoc2022/Day24.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ class Day24(private val lines: List<String>) {
private val end = lines.last().lastIndexOf('.') to lines.lastIndex

@Suppress("ComplexCondition")
private fun isFree(x: Int, y: Int, time: Int): Boolean {
private fun isFree(x: Int, y: Int, time: Int): Boolean =
if (x <= 0 || y <= 0 || y >= lines.lastIndex || x >= lines.getOrElse(y) { "" }.lastIndex) {
return (lines.getOrNull(y)?.getOrNull(x) ?: '#') == '.'
lines.getOrNull(y)?.getOrNull(x) == '.'
} else {
lines[y][(x - 1 + time).mod(lines[y].length - 2) + 1] != '<' &&
lines[y][(x - 1 - time).mod(lines[y].length - 2) + 1] != '>' &&
lines[(y - 1 + time).mod(lines.size - 2) + 1][x] != '^' &&
lines[(y - 1 - time).mod(lines.size - 2) + 1][x] != 'v'
}
return lines[y][(x - 1 + time).mod(lines[y].length - 2) + 1] != '<' &&
lines[y][(x - 1 - time).mod(lines[y].length - 2) + 1] != '>' &&
lines[(y - 1 + time).mod(lines.size - 2) + 1][x] != '^' &&
lines[(y - 1 - time).mod(lines.size - 2) + 1][x] != 'v'
}

private fun search(start: IntPair, end: IntPair, startTime: Int = 0): Int {
val (endX, endY) = end
Expand Down

0 comments on commit 91d0716

Please sign in to comment.