Exemplo n.º 1
0
 def __init__(self, code, default=BLACK):
     self.brain = IntCodeComputer2(code, True, False, False)
     self.direction = UP
     self.position = [0, 0]
     if default == BLACK:
         self.map = {(0, 0): 0}
     else:
         self.map = {(0, 0): 1}
     self.mem = set([])
     self.defVal = default
     self.paintCount = 0
Exemplo n.º 2
0
from aocd.models import Puzzle
from int_code_computer2 import IntCodeComputer2, STATUS_END_OF_PROGRAM, STATUS_STOP_ON_OUTPUT, STATUS_NEED_INPUT

puzzle = Puzzle(year=2019, day=15)

prog = [int(x)
        for x in puzzle.input_data.split(",")] + [0 for i in range(0, 6000)]
comp = IntCodeComputer2(prog, True, False, False)

comp.reset()

output = []
map = {}

NORTH = "1"
SOUTH = "2"
EAST = "4"
WEST = "3"

WALL = 0
STEP = 1
OXYGEN = 2

trylist = [NORTH, EAST, WEST, SOUTH]
result = None
while len(trylist) > 0:
    run = trylist.pop(0)
    if result is not None:
        if (len(run) > result + 1):
            break
    #jj mam neomezene robotu tak nac se vracet :-)
Exemplo n.º 3
0
from aocd.models import Puzzle
from itertools import permutations
from int_code_computer2 import IntCodeComputer2, STATUS_END_OF_PROGRAM

puzzle = Puzzle(year=2019, day=7)

prog = [int(x) for x in puzzle.input_data.split(",")]

phase_permutation = permutations([5, 6, 7, 8, 9], 5)

allampl = [IntCodeComputer2(prog, True, False, False) for x in range(0, 5)]
print(allampl)

bestPh = None
maximumTrust = 0
for phases in phase_permutation:
    out = 0
    inp = 0
    for i in range(0, 5):
        allampl[i].reset()
        allampl[i].addInput(phases[i])
    first = True
    while not allampl[0].status == STATUS_END_OF_PROGRAM:
        for i in range(0, 5):
            allampl[i].addInput(inp)
            allampl[i].run()
            out = allampl[i].output
            inp = out
        first = False
    if out > maximumTrust:
        maximumTrust = out
Exemplo n.º 4
0
from aocd.models import Puzzle
from int_code_computer2 import IntCodeComputer2
puzzle = Puzzle(year=2019, day=5)




prog=[ int(x)  for x in puzzle.input_data.split(",") ]


comp =IntCodeComputer2(prog)
comp.addInput(1)
ret =comp.run()

result =comp.output
print("2019-Day5-A result:", result)
puzzle.answer_a=result