Day 18 part 2
This commit is contained in:
parent
e0547c2309
commit
4807b2a033
1 changed files with 24 additions and 0 deletions
|
@ -22,4 +22,28 @@ fun main() {
|
|||
.map { it to 1 }
|
||||
})
|
||||
println("Part 1: $distance")
|
||||
|
||||
|
||||
val input = readInput("day18.txt")
|
||||
.map {
|
||||
val (a, b) = it.split(',', limit = 2)
|
||||
Grid.Coordinate(a.toInt(), b.toInt())
|
||||
}
|
||||
|
||||
val mem = CharGrid(size, size, '.')
|
||||
for (location in input) {
|
||||
mem[location] = '#'
|
||||
|
||||
val isStopped = dijkstra(start, goal = { it == goal }, neighbors = { pos ->
|
||||
Direction.entries.asSequence()
|
||||
.map { pos.step(it) }
|
||||
.filter { it in mem && mem[it] == '.' }
|
||||
.map { it to 1 }
|
||||
}) == null
|
||||
|
||||
if (isStopped) {
|
||||
println("Part 2: ${location.x},${location.y}")
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue