File tree 1 file changed +44
-6
lines changed 1 file changed +44
-6
lines changed Original file line number Diff line number Diff line change 2
2
//
3
3
// Part 1: Do a BFS to find all reachable nodes within 64 steps.
4
4
5
- func readInput( ) -> [ [ Character ] ] {
6
- var result : [ [ Character ] ] = [ ]
5
+ typealias Map = [ [ Character ] ]
6
+ typealias Coordinate = ( x: Int , y: Int )
7
+
8
+ struct Grid {
9
+ let map : Map
10
+ let start : Coordinate
11
+ let max : Coordinate
12
+
13
+ init ( map: Map ) {
14
+ self . map = map
15
+ self . start = Grid . findStart ( map)
16
+ self . max = ( map [ 0 ] . count, map. count)
17
+ }
18
+
19
+ static func findStart( _ map: Map ) -> Coordinate {
20
+ for (y, row) in map. enumerated ( ) {
21
+ for (x, c) in row. enumerated ( ) {
22
+ if c == " S " { return ( x, y) }
23
+ }
24
+ }
25
+ fatalError ( )
26
+ }
27
+
28
+ func neighbours( of c: Coordinate ) -> [ Coordinate ] {
29
+ return [ ]
30
+ }
31
+ }
32
+
33
+ extension Grid : CustomStringConvertible {
34
+ var description : String {
35
+ map. map { String ( $0) } . joined ( separator: " \n " )
36
+ }
37
+ }
38
+
39
+ func readInput( ) -> Grid {
40
+ var map : Map = [ ]
7
41
while let line = readLine ( ) {
8
- result . append ( Array ( line) )
42
+ map . append ( Array ( line) )
9
43
}
10
- return result
44
+ return Grid ( map : map )
11
45
}
12
46
13
- let map = readInput ( )
14
- print ( map)
47
+ // func bfs(_ map: Map) -> Int {
48
+ // var visited: Set
49
+ // }
50
+
51
+ let grid = readInput ( )
52
+ print ( grid)
You can’t perform that action at this time.
0 commit comments