@@ -266,10 +266,10 @@ func shortestPath(grid: Grid, start: Grid.Index, visit: Visitor? = nil
266
266
}
267
267
268
268
func trace( state: DijkstraState ) {
269
- if state. iteration % 500 == 0 {
270
- let total = grid. totalItems
271
- print ( " iteration \( state. iteration) found tentative distances to \( state. distance. count) / \( total) items " )
272
- }
269
+ // if state.iteration % 500 == 0 {
270
+ // let total = state. grid.totalItems
271
+ // print("iteration \(state.iteration) found tentative distances to \(state.distance.count) / \(total) items")
272
+ // }
273
273
}
274
274
275
275
extension Grid {
@@ -409,13 +409,11 @@ let validMovesP1 = 0...3
409
409
/// a maximum of 10 blocks before we must turn.
410
410
let validMovesP2 = 4 ... 10
411
411
412
+ /// A driver function
413
+ func sp( _ input: [ [ Int ] ] , _ validMoves: ClosedRange < Int > ) -> Int {
414
+ let grid = Grid ( items: input, validMoves: validMoves)
415
+ return ourShortestPath ( grid: grid) ?? - 1
416
+ }
417
+
412
418
let input = readInput ( )
413
- let grid = Grid ( items: input, validMoves: validMovesP2)
414
- let sp = ourShortestPath ( grid: grid)
415
- print ( " shortest-path-result " , sp ?? - 1 )
416
-
417
- // for i in 0..<1 {
418
- // let u = Grid.Index(xy: .init(x: 0, y: 0), heading: .east, moves: i)
419
- // print("")
420
- // printNeighbours(u, grid: grid)
421
- // }
419
+ print ( sp ( input, validMovesP1) , sp ( input, validMovesP2) )
0 commit comments