Skip to content

Commit 6849ece

Browse files
committed
Try penalizing long sequences
1 parent 5faf1dc commit 6849ece

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

day21/src/day21.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ extension (ptype: PadType) {
3636

3737
def shortestPath(startPos: Vec2, endPos: Vec2): String =
3838
case class Node(pos: Vec2, program: String = "") extends Ordered[Node] {
39-
def compare(that: Node): Int = that.program.length compare program.length // Intentionally reversed for min-heap
39+
def cost = program.length - "^^+|vv+|<<+|>>+".r.findAllMatchIn(program).length
40+
41+
def compare(that: Node): Int = that.cost compare cost // Intentionally reversed for min-heap
4042
}
4143

4244
val queue = mutable.PriorityQueue[Node]()
@@ -218,6 +220,8 @@ def moveCount(robots: Int, current: Char, next: Char): Int =
218220
// println(s"Part 1: ${solve(2, goals)}")
219221
// println(s"Part 2: ${solve(25, goals)}")
220222

223+
println(SHORTEST_PATHS)
224+
221225
for i <- (0 to 3) do
222226
println(s"${solve(i, goals, { (r, g) => shortestProgram(r, g).length })} vs ${solve(i, goals, shortestProgramLength)} vs ${solve(i, goals, shortestProgramLengthClever)}")
223227

0 commit comments

Comments
 (0)