You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
855 B

  1. require "advent"
  2. require "./intcode_fibers.cr"
  3. painted_white = Set({Int64, Int64}).new
  4. color = {} of {Int64,Int64} => Int64
  5. color[{0_i64, 0_i64}] = 1_i64
  6. input, output = new_interpreter("", input(2019, 11).split(",").map &.to_i64)
  7. pos = {0_i64, 0_i64}
  8. facing = {0_i64, 1_i64}
  9. struct Tuple(*T)
  10. def turn_left
  11. {-self[1], self[0]}
  12. end
  13. def turn_right
  14. turn_left.turn_left.turn_left
  15. end
  16. def add(other)
  17. {self[0] + other[0], self[1] + other[1]}
  18. end
  19. end
  20. loop do
  21. c = color[pos]? || 0_i64
  22. input.send c
  23. break unless nc = output.receive
  24. break unless turn = output.receive
  25. color[pos] = nc
  26. painted_white << pos if nc == 1
  27. facing = (turn == 0 ? facing.turn_left : facing.turn_right)
  28. pos = pos.add facing
  29. end
  30. 6.times do |y|
  31. y = - y
  32. 45.times do |x|
  33. print (color[{x.to_i64, y.to_i64}]? == 1 ? '#' : ' ')
  34. end
  35. puts
  36. end