53 lines
1.4 KiB
Python
53 lines
1.4 KiB
Python
from aoc import AOCDay
|
|
from coordinate import Coordinate
|
|
from grid import Grid
|
|
from intcode import IntCode
|
|
from typing import Any
|
|
|
|
|
|
MOVEMENTS = [Coordinate(0, -1), Coordinate(0, 1), Coordinate(-1, 0), Coordinate(1, 0)]
|
|
|
|
|
|
class Day(AOCDay):
|
|
test_solutions_p1 = []
|
|
test_solutions_p2 = []
|
|
|
|
def part1(self) -> Any:
|
|
comp = IntCode(self.getInputAsArraySplit(",", int))
|
|
comp.start()
|
|
pos = Coordinate(0, 0)
|
|
ox_pos = None
|
|
area = Grid()
|
|
while ox_pos is None:
|
|
madeMove = Coordinate(0, 0)
|
|
for i, move in enumerate(MOVEMENTS):
|
|
if not area.isSet(pos + move):
|
|
print("Trying to move to", pos + move)
|
|
comp.addInput(i + 1)
|
|
madeMove = move
|
|
break
|
|
|
|
reply = comp.getOutput()
|
|
print("comp replied with", reply)
|
|
if reply == 0:
|
|
area.set(pos + madeMove)
|
|
elif reply == 1:
|
|
pos += madeMove
|
|
else:
|
|
ox_pos = pos + madeMove
|
|
|
|
for y in range(area.minY, area.maxY + 1):
|
|
for x in range(area.minX, area.maxX + 1):
|
|
if area.isSet(Coordinate(x, y)):
|
|
print("#", end="")
|
|
else:
|
|
print(" ", end="")
|
|
|
|
print()
|
|
|
|
print("Oxygen System found at", ox_pos)
|
|
|
|
|
|
def part2(self) -> Any:
|
|
return ""
|