@@ -6,6 +6,7 @@ import me.underlow.advent2022.checkResult
66import me.underlow.advent2022.readInput
77import me.underlow.get
88import me.underlow.isPointInside
9+ import java.util.*
910import kotlin.math.min
1011
1112object 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
286288fun 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