Skip to content

Commit a7dbcfd

Browse files
committed
Implement part 2 naively
1 parent 77a9fb1 commit a7dbcfd

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

day21/src/day21.scala

+10-12
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,14 @@ def shortestProgram(startState: State, goal: String): String =
102102

103103
throw new RuntimeException("No shortest program found")
104104

105-
@main def main(path: String) =
106-
val input = Source.fromFile(path).getLines.toList
105+
def solve(robots: Int, goals: List[String]): Int =
106+
val pads = List.fill(robots)(Pad(PadType.Dir)) :+ Pad(PadType.Num)
107+
goals.map { goal =>
108+
val shortest = shortestProgram(State(pads), goal)
109+
shortest.length * goal.dropRight(1).toInt
110+
}.sum
107111

108-
val part1 = (
109-
for
110-
goal <- input
111-
yield
112-
val pads = List(PadType.Dir, PadType.Dir, PadType.Num).map(Pad(_))
113-
val shortest = shortestProgram(State(pads), goal)
114-
shortest.length * goal.dropRight(1).toInt
115-
).sum
116-
117-
println(s"Part 1: $part1")
112+
@main def main(path: String) =
113+
val goals = Source.fromFile(path).getLines.toList
114+
println(s"Part 1: ${solve(2, goals)}")
115+
println(s"Part 2: ${solve(25, goals)}")

0 commit comments

Comments
 (0)