File tree 1 file changed +10
-12
lines changed
1 file changed +10
-12
lines changed Original file line number Diff line number Diff line change @@ -102,16 +102,14 @@ def shortestProgram(startState: State, goal: String): String =
102
102
103
103
throw new RuntimeException (" No shortest program found" )
104
104
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
107
111
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)}" )
You can’t perform that action at this time.
0 commit comments