def play(self, mode='a'): memory = self.memory[:] self.comp = opComp(memory, outlen=self.outlen) self.comp.set_memory(0, 2) # print(self.ball, self.paddle) # test_inp = 'ddsaddddddddddddddddddddddddddddddddddd' test = 1 self.prev = self.ball while not self.comp.finished: inp = self.smart_paddle() bx, by, id = self.comp.run_prog(inp=inp, ret=True) if id == 4: self.prev = self.ball self.ball = (bx, by) t = [ each for each in [(bx + 1, by), (bx - 1, by), (bx, by - 1), (bx, by + 1)] if each in self.blocks ] for each in t: self.blocks.remove(each) # print(self) # time.sleep(1) if test > 100 and False: break else: print(f"Exit: {[bx,by,id]}, finsihed: {self.comp.finished}") print(len(self.blocks))
def test(): program = get_input(test=True) for each in program: c1 = opComp(each, inp=2) print( f"codes ran: { c1.opcodes_run}, l: {len(str(c1.output))} out: {c1.output}" )
def __init__(self, inp = None, memory = None, outlen = 1): self.wall = Tile() self.pos = (0,0) self.root = Tile( ) self.current = Tile( (self.pos) ) self.root.next.append(self.current) self.current.previous = self.root self.grid = { self.pos : self.current} self.path = [] if inp == None: inp = get_input(r'Day_15\input.txt') self.inp = inp self.brain = opComp(memory=self.inp[:], outlen=outlen) self.num_commands = { 1 : 'n', 2 : 's', 3 : 'w', 4 : 'e'} self.commands = {'n': 1, 's': 2, 'w': 3, 'e': 4} self.reverse_commands = {'n': 's', 's': 'n', 'w': 'e', 'e': 'w'} self.coords = {'n':(0,-1), 's':(0,1), 'w':(-1,0), 'e':(1,0)} self.run()
def __init__(self): memory = get_input() self.comp = opComp(memory) self.pos = (0, 0) self.dir = '^' self.visited = [] self.move_logic = { '^': { 0: '<', 1: '>' }, '>': { 0: '^', 1: 'v' }, 'v': { 0: '>', 1: '<' }, '<': { 0: 'v', 1: '^' } } self.pos_logic = {'^': (0, -1), '>': (1, 0), 'v': (0, 1), '<': (-1, 0)} self.white = set()
def __init__(self, outlen=None, inp=None, memory=None): if memory == None: memory = get_input() self.memory = memory[:] self.comp = opComp(memory[:], outlen=outlen) self.outlen = outlen self.wall = '#' self.inp_map = {1: 'N', 2: 'S', 3: 'W', 4: 'E'} self.inp_map_rev = {'S': 1, 'N': 2, 'E': 3, 'W': 4} self.directions = list(self.inp_map.keys())
def __init__(self, inp=None, outlen=1): memory = get_input() self.memory = memory[:] self.comp = opComp(memory[:], outlen=outlen) self.outlen = outlen self.tile_ids = {0: ' ', 1: '|', 2: '#', 3: '~', 4: 'O'} self.inp_map = {'a': -1, 's': 0, 'd': 1} self.comp.run_prog(inp) if self.comp.opcodes_run == 0: print(f'No code was executed, finished: {self.comp.finished}') inst = self.comp.instructions() self.test = inst rx, ry = self.game_dims(inst) game = [] for y in ry: game.append([]) for _ in rx: game[y].append([]) self.ball = None self.paddle = None self.blocks = set() for i in inst: x, y, id = i game[y][x] = id if id == 2: self.blocks.add((x, y)) elif id == 4: self.ball = (x, y) elif id == 3: self.paddle = (x, y) if not self.ball and not self.paddle: print('shits f****d') self.game = game
lines = lines[0] return lines import time t0 = time.time() program = get_input() seq = sequencer([i for i in range(5, 10)]) part2 = 0 for A, B, C, D, E in seq: counter = 0 cA = opComp(program, inp=A) cB = opComp(program, inp=B) cC = opComp(program, inp=C) cD = opComp(program, inp=D) cE = opComp(program, inp=E) done = sum([int(each.finished) for each in [cA, cB, cC, cD, cE]]) print(done) Ain = 0 counter = 0 limit = 1000 while not done and counter < limit: Bin = cA.run_prog(Ain) Cin = cB.run_prog(Bin)
print( f"codes ran: { c1.opcodes_run}, l: {len(str(c1.output))} out: {c1.output}" ) if __name__ == "__main__" or True: t0 = time.time() """ ------------------------------------------------------------------------------------------------------------------ """ debug = False if debug: test() part1 = None else: program = get_input() c1 = opComp(program, inp=1) print( f"codes ran: { c1.opcodes_run}, l: {len(str(c1.output))} out: {c1.output}" ) part1 = c1.output[0] t1 = time.time() """ ------------------------------------------------------------------------------------------------------------------ """ program = get_input() c1 = opComp(program, inp=2) print( f"codes ran: { c1.opcodes_run}, l: {len(str(c1.output))} out: {c1.output}" ) part2 = c1.output[0]