@main struct Day13: Puzzle { var maxX: Int = 0 var maxY: Int = 0 mutating func run() { maxX = dots.map(\.x).max()! maxY = dots.map(\.y).max()! for (pos, fold) in folds.enumerated() { self.fold(fold) if (pos == 0) { print("Part 1:", Set(dots).count) } } print("\n\nPart 2:\n") for y in 0..= x { print(String(repeating: ".", count: dotX - x) + "#", terminator: "") x = dotX + 1 } print(String(repeating: ".", count: maxX - x)) } } mutating func fold(_ fold: Fold) { switch fold { case .x(let axis): self.fold(at: axis, keyPath: \.x, max: maxX) maxX = axis case .y(let axis): self.fold(at: axis, keyPath: \.y, max: maxY) maxY = axis } } mutating func fold(at limit: Int, keyPath: WritableKeyPath, max: Int) { let mid = dots.partition { dot in dot[keyPath: keyPath] > limit } for index in mid..