@@ -5,6 +5,8 @@ class TractorBeam {
55 constructor ( memory , options = { } ) {
66 this . memory = memory . slice ( 0 ) ;
77 this . grid = new InfiniteGrid ( { string_map : { 1 : '#' , 0 : '.' } } ) ;
8+
9+ this . parseOpTime = 0 ;
810 }
911
1012 partOne ( ) {
@@ -192,22 +194,14 @@ class TractorBeam {
192194 // First, move down until we hit 0
193195 do {
194196 bottom_edge . y ++ ;
195- let computer = new Computer ( {
196- memory : this . memory ,
197- inputs : [ bottom_edge . x , bottom_edge . y ] ,
198- } ) ;
199- [ output ] = computer . run ( ) ;
197+ output = this . computeAt ( bottom_edge . x , bottom_edge . y ) ;
200198 this . grid . set ( bottom_edge . x , bottom_edge . y , output ) ;
201199 } while ( output === 1 ) ;
202200
203201 // Then, move inward until we hit a `1`
204202 do {
205203 bottom_edge . x ++ ;
206- let computer = new Computer ( {
207- memory : this . memory ,
208- inputs : [ bottom_edge . x , bottom_edge . y ] ,
209- } ) ;
210- [ output ] = computer . run ( ) ;
204+ output = this . computeAt ( bottom_edge . x , bottom_edge . y ) ;
211205 this . grid . set ( bottom_edge . x , bottom_edge . y , output ) ;
212206 } while ( output === 0 ) ;
213207 }
@@ -220,11 +214,7 @@ class TractorBeam {
220214 do {
221215 // Move right until we hit a `0`
222216 top_edge . x ++ ;
223- let computer = new Computer ( {
224- memory : this . memory ,
225- inputs : [ top_edge . x , top_edge . y ] ,
226- } ) ;
227- [ output ] = computer . run ( ) ;
217+ output = this . computeAt ( top_edge . x , top_edge . y ) ;
228218 this . grid . set ( top_edge . x , top_edge . y , output ) ;
229219 } while ( output === 1 ) ;
230220 } while ( allow_for_bottom_jumps && top_edge . y !== bottom_edge . y ) ;
@@ -242,6 +232,8 @@ class TractorBeam {
242232 // The computer halts after every output, so we create a new one each time
243233 let computer = new Computer ( { memory : this . memory , inputs : [ x , y ] } ) ;
244234 let [ output ] = computer . run ( ) ;
235+ this . parseOpTime += computer . parseOpTime ;
236+
245237 return output ;
246238 }
247239}
0 commit comments