Skip to content

Commit 07c96a1

Browse files
committed
🎉
1 parent eca014e commit 07c96a1

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

17.p2-expand-opt.swift

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,10 @@ func shortestPath(grid: Grid, start: Grid.Index, visit: Visitor? = nil
266266
}
267267

268268
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+
// }
273273
}
274274

275275
extension Grid {
@@ -409,13 +409,11 @@ let validMovesP1 = 0...3
409409
/// a maximum of 10 blocks before we must turn.
410410
let validMovesP2 = 4...10
411411

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+
412418
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

Comments
 (0)