Skip to content

Commit 1716ac9

Browse files
committed
2023/day 17 - part 2
1 parent ddd8530 commit 1716ac9

File tree

1 file changed

+8
-6
lines changed
  • src/main/kotlin/me/underlow/advent2023

1 file changed

+8
-6
lines changed

src/main/kotlin/me/underlow/advent2023/Day17.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import me.underlow.advent2022.checkResult
66
import me.underlow.advent2022.readInput
77
import me.underlow.get
88
import me.underlow.isPointInside
9+
import java.util.*
910
import kotlin.math.min
1011

1112
object ClumsyCrucible {
@@ -189,14 +190,15 @@ object ClumsyCrucible {
189190

190191
val cache = mutableMapOf<Crucible, Int>()
191192

192-
val tasks = mutableListOf<Task>()
193+
// val tasks = mutableListOf<Task>()
194+
val tasks = PriorityQueue { t1: Task, t2: Task -> t1.heat - t2.heat }
193195
tasks += Task(Crucible(Point(0, 0), Dir.Right, 0), 0)
194196
tasks += Task(Crucible(Point(0, 0), Dir.Down, 0), 0)
195197

196198
var result = Int.MAX_VALUE
197199

198200
while (tasks.isNotEmpty()) {
199-
val task = tasks.removeLast()
201+
val task = tasks.poll()
200202
val crucible = task.crucible
201203

202204
if (tasks.size % 50000 == 0) {
@@ -285,12 +287,12 @@ object ClumsyCrucible {
285287

286288
fun main() {
287289
val input = readInput("$pathPrefix23/day17.txt")
288-
// val res1 = ClumsyCrucible.part1(input)
290+
val res1 = ClumsyCrucible.part1(input)
289291
val res2 = ClumsyCrucible.part22(input)
290292

291-
// println("part 1: $res1")
293+
println("part 1: $res1")
292294
println("part 2: $res2")
293295

294-
// checkResult(res1, 684) // 999 high
295-
checkResult(res2, 0) // 823 high
296+
checkResult(res1, 684) // 999 high
297+
checkResult(res2, 822) // 823 high
296298
}

0 commit comments

Comments
 (0)