diff --git a/Sources/AdventOfCode19/Solutions/Day11.swift b/Sources/AdventOfCode19/Solutions/Day11.swift index 52efecc..61fce18 100644 --- a/Sources/AdventOfCode19/Solutions/Day11.swift +++ b/Sources/AdventOfCode19/Solutions/Day11.swift @@ -34,7 +34,7 @@ final class Day11: Day { func solvePartTwo() -> CustomStringConvertible { let painter = Painter(program: data, startColor: .white) painter.run() - return "\n" + painter.asciiArt + return "\n" + painter.asciiArt() } } @@ -123,19 +123,21 @@ extension Day11 { } } + // initial conditions + let initialProgram: [Int] + let startColor: Color + + // painter state var facing: Direction = .up var coordinate: Coordinate = Coordinate(x: 0, y: 0) var visited = [Coordinate: Color]() - let computer: Intcode - init(program: [Int], startColor: Color) { - let input = Intcode.sparseInput(from: program) - let computer = Intcode(data: input, inputs: [startColor.rawValue]) - self.computer = computer + self.initialProgram = program + self.startColor = startColor } - var asciiArt: String { + func asciiArt(flipVertical: Bool = true) -> String { // figure out the region that is actually filled in, // so we can allocate an array of the right size let minX = visited.keys.min(by: { $0.x < $1.x })! @@ -145,16 +147,17 @@ extension Day11 { let maxY = visited.keys.min(by: { $0.y > $1.y })! let rangeY = maxY.y - minY.y + 1 // intialise output area - var output: [[Color]] = Array(repeating: [], count: rangeY) - for i in 0..