64 lines
1.6 KiB
Python
64 lines
1.6 KiB
Python
from intcode import IntCode
|
|
from tools.aoc import AOCDay
|
|
from tools.coordinate import Coordinate
|
|
from tools.grid import Grid
|
|
from typing import Any
|
|
|
|
|
|
MOVEMENTS = [Coordinate(0, -1), Coordinate(0, 1), Coordinate(-1, 0), Coordinate(1, 0)]
|
|
|
|
|
|
class Day(AOCDay):
|
|
inputs = [
|
|
[
|
|
(None, "input15")
|
|
],
|
|
[
|
|
(None, "input15")
|
|
]
|
|
]
|
|
|
|
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 ""
|
|
|
|
|
|
if __name__ == '__main__':
|
|
day = Day(15)
|
|
day.run(verbose=True)
|