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.

5 年之前
5 年之前
5 年之前
123456789101112131415161718192021222324252627282930313233
  1. import collections
  2. import sys
  3. from intcode import compute
  4. def get_panels(ns, start):
  5. feedback = [start]
  6. iter_in = iter(feedback)
  7. robot = compute(ns, iter_in)
  8. pos, ori = 0, -1j
  9. panels = collections.defaultdict(int)
  10. for paint, instruction in zip(robot, robot):
  11. panels[pos] = paint
  12. ori *= 1j if instruction else -1j
  13. pos += ori
  14. feedback.append(panels[pos])
  15. return panels
  16. def visualize(panels, brush):
  17. xmin, *_, xmax = sorted(int(p.real) for p in panels)
  18. ymin, *_, ymax = sorted(int(p.imag) for p in panels)
  19. for y in range(ymin, ymax + 1):
  20. for x in range(xmin, xmax + 1):
  21. print(brush[panels[complex(x, y)]], end='')
  22. print()
  23. text = sys.stdin.read()
  24. print(len(get_panels(text, 0)))
  25. visualize(get_panels(text, 1), brush=' #')