Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using IntCode
- function part1(input::AbstractString)
- robot = Computer(input)
- dir, pos = im, 0im
- colors = Dict{typeof(pos), Int}()
- while robot.halt == false
- paint, turn = robot(get!(colors, pos, 0))
- dir = turn == 0 ? dir * im : dir * -im
- colors[pos] = paint
- pos += dir
- end
- return length(colors)
- end
- function part2(input::AbstractString)
- robot = Computer(input)
- dir, pos = im, 0im
- colors = Dict{typeof(pos), Int}()
- colors[0] = 1
- while robot.halt == false
- paint, turn = robot(get!(colors, pos, 0))
- colors[pos] = paint
- dir = turn == 0 ? dir * im : dir * -im
- pos += dir
- end
- xmin, xmax = extrema(real.(keys(colors)))
- ymin, ymax = extrema(imag.(keys(colors)))
- for y ∈ ymax:-1:ymin
- println(join(get(colors, complex(x, y), 0) == 1 ? '█' : ' ' for x ∈ xmin:xmax))
- end
- end
- input = read("input_11.txt", String)
- println("Part 1: ", part1(input))
- println("Part 2: ")
- part2(input)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement