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.
AdventOfCode19/days/test_day11.py

48 lines
1.5 KiB

import os
from .comp import OpcodeComputer
inputfile = os.path.join(os.path.dirname(__file__), "input/day11_input")
def test_day11a():
area = {}
pos = (0, 0)
pipe = [0]
comp = OpcodeComputer(inputfile).process_op(pipe)
i = 0
dirs = [(0, -1), (-1, 0), (0, 1), (1, 0)]
for color in comp:
area[pos] = color
i += 1 if comp.__next__() == 0 else -1
pos = (dirs[i % 4][0] + pos[0], dirs[i % 4][1] + pos[1])
pipe.append(1 if area.get(pos) == 1 else 0)
assert len(area) == 2469
def test_day11b():
result = ''
area = {}
pos = (0, 0)
pipe = [1]
comp = OpcodeComputer(inputfile).process_op(pipe)
i = 0
dirs = [(0, -1), (-1, 0), (0, 1), (1, 0)]
for color in comp:
area[pos] = color
i += 1 if comp.__next__() == 0 else -1
pos = (dirs[i % 4][0] + pos[0], dirs[i % 4][1] + pos[1])
pipe.append(1 if area.get(pos) == 1 else 0)
for y in range(max(area.keys(), key=lambda i: i[1])[1] + 1):
for x in range(max(area.keys(), key=lambda i: i[0])[0] + 1):
result += '#' if area.get((x, y)) == 1 else ' '
result += '\n'
expected = """\
# # # ## #### ## #### ## # #
# # # # # # # # # # # # #
## # # # # # ### # # #
# # # # # #### # # ## # #
# # # # # # # # # # # # #
# # #### ## #### # # #### ### ##
"""
assert result == expected