more debugging printouts
This commit is contained in:
		| @@ -44,10 +44,13 @@ struct Map: CustomStringConvertible { | |||||||
|         var s: [[String]] = Array( |         var s: [[String]] = Array( | ||||||
|             repeating: Array(repeating: "  ", count: w*2), count: h |             repeating: Array(repeating: "  ", count: w*2), count: h | ||||||
|         ) |         ) | ||||||
|         walls.forEach { w in s[w.y][w.x] = "██" } |         walls.forEach { w in s[w.y][w.x] = "🮘🮘" } | ||||||
|         boxes.boxes.forEach { b in s[b.y][b.x] = "🮇🮀"; s[b.y][b.x+1] = "🮀▌" } |         boxes.boxes.forEach { b in s[b.y][b.x] = "🬴🬰"; s[b.y][b.x+1] = "🬰🬸" } | ||||||
|         s[bot.y][bot.x] = "🮕🮕" |         s[bot.y][bot.x] = "\u{001B}[91m🮿 \u{001B}[0m" | ||||||
|         return s.map { row in row.joined() }.joined(separator: "\n") |         return ("    " + (0..<w).map { String(format: "%4d", $0 % 1000) }.joined() + "\n") + | ||||||
|  |             s.enumerated().map { | ||||||
|  |                 i, row in String(format: "%3d ", i) + row.joined() | ||||||
|  |             }.joined(separator: "\n") | ||||||
|     } |     } | ||||||
|     var gps: Int { return boxes.boxes.reduce(0) { s, box in s + box.gps } } |     var gps: Int { return boxes.boxes.reduce(0) { s, box in s + box.gps } } | ||||||
|  |  | ||||||
| @@ -106,10 +109,11 @@ func readInput(_ filePath: String) throws -> (Map, [Move]) { | |||||||
| } | } | ||||||
|  |  | ||||||
| var (map, moves) = try readInput(CommandLine.arguments[1]) | var (map, moves) = try readInput(CommandLine.arguments[1]) | ||||||
| print(map) |  | ||||||
| print(moves) | print(moves) | ||||||
| for move in moves { | for move in moves { | ||||||
|  |     print(map) | ||||||
|     map.move(move) |     map.move(move) | ||||||
|  |     print(move) | ||||||
| } | } | ||||||
| print(map) | print(map) | ||||||
| print(map.gps) | print(map.gps) | ||||||
|   | |||||||
| @@ -58,8 +58,8 @@ struct Maze : CustomStringConvertible { | |||||||
|         let s: [[String]] = walls.enumerated().map { i, r in |         let s: [[String]] = walls.enumerated().map { i, r in | ||||||
|             [String(format: "%3d ", i)] + r.map { $0 ? "██" : "  " } |             [String(format: "%3d ", i)] + r.map { $0 ? "██" : "  " } | ||||||
|         } |         } | ||||||
|         print("    " + (0..<w).map { " \($0 % 10)" }.joined()) |         return ("    " + (0..<w).map { " \($0 % 10)" }.joined()) + | ||||||
|         return s.map { $0.joined() }.joined(separator: "\n") |             s.map { $0.joined() }.joined(separator: "\n") | ||||||
|     } |     } | ||||||
|     init(fromFile f: String) throws { |     init(fromFile f: String) throws { | ||||||
|         let content = try String(contentsOfFile: f, encoding: .ascii) |         let content = try String(contentsOfFile: f, encoding: .ascii) | ||||||
|   | |||||||
| @@ -146,6 +146,7 @@ struct AoC { | |||||||
|     static func main() throws { |     static func main() throws { | ||||||
|         let maze = try Maze(fromFile: CommandLine.arguments[1]) |         let maze = try Maze(fromFile: CommandLine.arguments[1]) | ||||||
|         let (graph, pathPairs) = maze.graph() |         let (graph, pathPairs) = maze.graph() | ||||||
|  |         print("maze: \(maze.w)x\(maze.h) intersections: \(graph.count)") | ||||||
|         let visited = search(graph: graph, start: maze.start) |         let visited = search(graph: graph, start: maze.start) | ||||||
|         let minCost = maze.ends.compactMap { visited[$0] }.map { $0.0 }.min()! |         let minCost = maze.ends.compactMap { visited[$0] }.map { $0.0 }.min()! | ||||||
|         print("minCost: \(minCost)") |         print("minCost: \(minCost)") | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user