File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -102,14 +102,21 @@ def shortestProgramLength(startState: State, goal: String): Int =
102
102
103
103
throw new RuntimeException (" No shortest program found" )
104
104
105
+ def makePads (robots : Int ): List [Pad ] = List .fill(robots)(Pad (PadType .Dir )) :+ Pad (PadType .Num )
106
+
107
+ def makeState (robots : Int ) = State (makePads(robots))
108
+
105
109
def solve (robots : Int , goals : List [String ]): Int =
106
- val pads = List .fill (robots)( Pad ( PadType . Dir )) :+ Pad ( PadType . Num )
110
+ val state = makeState (robots)
107
111
goals.map { goal =>
108
- val shortest = shortestProgramLength(State (pads) , goal)
112
+ val shortest = shortestProgramLength(state , goal)
109
113
shortest * goal.dropRight(1 ).toInt
110
114
}.sum
111
115
112
116
@ main def main (path : String ) =
113
117
val goals = Source .fromFile(path).getLines.toList
114
- println(s " Part 1: ${solve(2 , goals)}" )
115
- println(s " Part 2: ${solve(25 , goals)}" )
118
+ // println(s"Part 1: ${solve(2, goals)}")
119
+ // println(s"Part 2: ${solve(25, goals)}")
120
+
121
+ for c <- ('0' to '9' ) do
122
+ println(s " $c -> ${(0 to 8 ).map { i => shortestProgramLength(makeState(i), s " $c" ) }}" )
You can’t perform that action at this time.
0 commit comments