day(06): refactor getting initial position
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
b78c91e5db
commit
d62bdd1807
1 changed files with 10 additions and 10 deletions
20
src/Day06.kt
20
src/Day06.kt
|
@ -6,20 +6,20 @@ class Day06(
|
||||||
private val map: Array<CharArray> = readInput(6, inputType).map { it.toCharArray() }.toTypedArray()
|
private val map: Array<CharArray> = readInput(6, inputType).map { it.toCharArray() }.toTypedArray()
|
||||||
|
|
||||||
private val initialPosition: Vector =
|
private val initialPosition: Vector =
|
||||||
let {
|
map
|
||||||
for (row in map.withIndex()) {
|
.withIndex()
|
||||||
for (cell in row.value.withIndex()) {
|
.flatMap { row ->
|
||||||
if (cell.value == '^') {
|
row.value.withIndex().map { cell ->
|
||||||
return@let cell.index to row.index
|
(cell.index to row.index) to cell.value
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}.first { (_, cell) -> cell == '^' }
|
||||||
|
.let { (pos, _) -> pos }
|
||||||
|
|
||||||
error("there's always at least one guard")
|
private val route: Set<Vector> =
|
||||||
|
guard(null).let { (visited, _) ->
|
||||||
|
visited.map { (_, p) -> p }.toSet()
|
||||||
}
|
}
|
||||||
|
|
||||||
private val route: Set<Vector> = guard(null).let { (visited, _) -> visited.map { (_, p) -> p }.toSet() }
|
|
||||||
|
|
||||||
override fun precompute() {
|
override fun precompute() {
|
||||||
// no-op
|
// no-op
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue