Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 1.02 KB | None | 0 0
  1. using IntCode
  2.  
  3. function part1(input::AbstractString)
  4.     robot = Computer(input)
  5.     dir, pos = im, 0im
  6.     colors = Dict{typeof(pos), Int}()
  7.     while robot.halt == false
  8.         paint, turn = robot(get!(colors, pos, 0))
  9.         dir = turn == 0 ? dir * im : dir * -im
  10.         colors[pos] = paint
  11.         pos += dir
  12.     end
  13.     return length(colors)
  14. end
  15.  
  16. function part2(input::AbstractString)
  17.     robot = Computer(input)
  18.     dir, pos = im, 0im
  19.     colors = Dict{typeof(pos), Int}()
  20.     colors[0] = 1
  21.     while robot.halt == false
  22.         paint, turn = robot(get!(colors, pos, 0))
  23.         colors[pos] = paint
  24.         dir = turn == 0 ? dir * im : dir * -im
  25.         pos += dir
  26.     end
  27.     xmin, xmax = extrema(real.(keys(colors)))
  28.     ymin, ymax = extrema(imag.(keys(colors)))
  29.     for y ∈ ymax:-1:ymin
  30.         println(join(get(colors, complex(x, y), 0) == 1 ? '█' : ' ' for x in xmin:xmax))
  31.     end
  32. end
  33.  
  34. input = read("input_11.txt", String)
  35. println("Part 1: ", part1(input))
  36. println("Part 2: ")
  37. part2(input)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement