File tree 1 file changed +7
-12
lines changed
1 file changed +7
-12
lines changed Original file line number Diff line number Diff line change @@ -62,34 +62,29 @@ func readInput() -> Grid {
62
62
}
63
63
64
64
func bfs( grid: Grid , maxStep: Int ) -> Int {
65
- var visited : Set < Coordinate > = Set ( )
66
-
67
65
var pending = [ ( grid. start, 0 ) ]
68
66
var pi = 0
69
67
68
+ var lastCells : Set < Coordinate > = Set ( )
69
+
70
70
while pi < pending. count {
71
71
let ( c, step) = pending [ pi]
72
72
pi += 1
73
73
74
- if !visited. insert ( c) . inserted {
75
- continue
76
- }
77
-
78
74
if step == maxStep {
75
+ lastCells. insert ( c)
79
76
continue
80
77
}
81
78
82
79
for n in grid. neighbours ( of: c) {
83
- if !visited. contains ( n) {
84
- pending. append ( ( n, step + 1 ) )
85
- }
80
+ pending. append ( ( n, step + 1 ) )
86
81
}
87
82
}
88
83
89
- return visited . count
84
+ return lastCells . count
90
85
}
91
86
92
87
let grid = readInput ( )
93
- let c = bfs ( grid: grid, maxStep: 64 )
94
- print ( grid)
88
+ let c = bfs ( grid: grid, maxStep: 6 )
89
+ // print(grid)
95
90
print ( c)
You can’t perform that action at this time.
0 commit comments