import Foundation struct Point : Hashable { let x: Int let y: Int } func readInput(_ filePath: String) throws -> (Int, Int, [Character: [Point]]) { let content = try String(contentsOfFile: filePath, encoding: .ascii) let lines = content.split(separator: "\n").map(Array.init) let antennas = lines.enumerated().flatMap { i, line in line.enumerated().compactMap { j, cell in cell == "." ? nil : (cell, i, j) } } var map: [Character: [Point]] = [:] for (type, i, j) in antennas { let current = map[type, default: []] map[type] = current + [Point(x: i, y: j)] } return (lines.count, lines[0].count, map) } func nodes(_ antennas: [Point]) -> Set { var nodes: Set = [] for i in 0..= 0 && p.y >= 0 && p.x < height && p.y < width } .count print(answer)