def __init__(self): self.score = 0 self.field = [[' '] * 42 for i in range(24)] with open(FILE_PATH) as data: program = list(map(int, data.read().split(','))) self.c = Computer(program, wait_for_input=True) self.paddle = 0 self.ball = 0 self.c.program[0] = 2
from pprint import pprint from advents_of_code.common import Computer with open('advents_of_code/2019/day17.txt') as data: program = list(map(int, data.read().split(','))) c = Computer(program, wait_for_input=True) while not c.terminated: c.run_software() chars = ''.join([chr(code) for code in c.outputs]).split() pprint(chars) coll = 0 for y, row in enumerate(chars): for x, col in enumerate(row): try: if (chars[y][x] == '#' and chars[y - 1][x] == '#' and chars[y + 1][x] == '#' and chars[y][x - 1] == '#' and chars[y][x + 1] == '#'): coll += y * x except: pass print(coll)
1, 64, 1105, 1, 615, 4, 603, 1002, 64, 2, 64, 109, -10, 1205, 4, 633, 4, 621, 1001, 64, 1, 64, 1106, 0, 633, 1002, 64, 2, 64, 109, 2, 1206, 2, 645, 1106, 0, 651, 4, 639, 1001, 64, 1, 64, 1002, 64, 2, 64, 109, -4, 1202, -6, 1, 63, 1008, 63, 28, 63, 1005, 63, 671, 1105, 1, 677, 4, 657, 1001, 64, 1, 64, 1002, 64, 2, 64, 109, -9, 21102, 44, 1, 4, 1008, 1010, 44, 63, 1005, 63, 699, 4, 683, 1105, 1, 703, 1001, 64, 1, 64, 1002, 64, 2, 64, 109, 31, 2106, 0, -9, 4, 709, 1105, 1, 721, 1001, 64, 1, 64, 1002, 64, 2, 64, 109, -30, 21108, 45, 45, 6, 1005, 1013, 743, 4, 727, 1001, 64, 1, 64, 1106, 0, 743, 1002, 64, 2, 64, 109, 2, 21101, 46, 0, 3, 1008, 1012, 46, 63, 1005, 63, 765, 4, 749, 1106, 0, 769, 1001, 64, 1, 64, 1002, 64, 2, 64, 109, -5, 2101, 0, 0, 63, 1008, 63, 24, 63, 1005, 63, 795, 4, 775, 1001, 64, 1, 64, 1105, 1, 795, 1002, 64, 2, 64, 109, 6, 2107, 32, -1, 63, 1005, 63, 815, 1001, 64, 1, 64, 1106, 0, 817, 4, 801, 1002, 64, 2, 64, 109, 19, 2105, 1, -5, 4, 823, 1106, 0, 835, 1001, 64, 1, 64, 1002, 64, 2, 64, 109, -12, 21107, 47, 46, -1, 1005, 1016, 851, 1105, 1, 857, 4, 841, 1001, 64, 1, 64, 1002, 64, 2, 64, 109, -2, 1205, 5, 873, 1001, 64, 1, 64, 1105, 1, 875, 4, 863, 1002, 64, 2, 64, 109, -6, 2102, 1, -8, 63, 1008, 63, 23, 63, 1005, 63, 897, 4, 881, 1105, 1, 901, 1001, 64, 1, 64, 4, 64, 99, 21101, 0, 27, 1, 21101, 0, 915, 0, 1106, 0, 922, 21201, 1, 44808, 1, 204, 1, 99, 109, 3, 1207, -2, 3, 63, 1005, 63, 964, 21201, -2, -1, 1, 21101, 942, 0, 0, 1105, 1, 922, 21201, 1, 0, -1, 21201, -2, -3, 1, 21102, 957, 1, 0, 1105, 1, 922, 22201, 1, -1, -2, 1106, 0, 968, 21202, -2, 1, -2, 109, -3, 2105, 1, 0 ] comp = Computer(opt_input=2, program=program) while not comp.terminated: comp.run_software() print(comp.outputs)
838337188628, 1, 21101, 0, 446, 0, 1105, 1, 447, 99, 109, 2, 21202, -1, 1, 1, 21101, 40, 0, 2, 21102, 478, 1, 3, 21101, 0, 468, 0, 1106, 0, 511, 109, -2, 2106, 0, 0, 0, 1, 0, 0, 1, 109, 2, 3, 10, 204, -1, 1001, 473, 474, 489, 4, 0, 1001, 473, 1, 473, 108, 4, 473, 10, 1006, 10, 505, 1102, 1, 0, 473, 109, -2, 2106, 0, 0, 0, 109, 4, 2102, 1, -1, 510, 1207, -3, 0, 10, 1006, 10, 528, 21101, 0, 0, -3, 21202, -3, 1, 1, 22101, 0, -2, 2, 21101, 1, 0, 3, 21102, 1, 547, 0, 1106, 0, 552, 109, -4, 2106, 0, 0, 109, 5, 1207, -3, 1, 10, 1006, 10, 575, 2207, -4, -2, 10, 1006, 10, 575, 22102, 1, -4, -4, 1105, 1, 643, 22102, 1, -4, 1, 21201, -3, -1, 2, 21202, -2, 2, 3, 21101, 0, 594, 0, 1105, 1, 552, 21201, 1, 0, -4, 21101, 0, 1, -1, 2207, -4, -2, 10, 1006, 10, 613, 21101, 0, 0, -1, 22202, -2, -1, -2, 2107, 0, -3, 10, 1006, 10, 635, 22102, 1, -1, 1, 21101, 635, 0, 0, 106, 0, 510, 21202, -2, -1, -2, 22201, -4, -2, -4, 109, -5, 2106, 0, 0 ] c = Computer(p) n = 90 field = [[0 for x in range(n)] for y in range(n)] cursor = (n // 2, n // 2) direction = (-1, 0) transitions = { 0: { (-1, 0): (0, -1), (0, -1): (1, 0), (1, 0): (0, 1), (0, 1): (-1, 0) }, 1: {
class Game: tiles = {0: ' ', 1: 'X', 2: '#', 3: '_', 4: 'o'} def __init__(self): self.score = 0 self.field = [[' '] * 42 for i in range(24)] with open(FILE_PATH) as data: program = list(map(int, data.read().split(','))) self.c = Computer(program, wait_for_input=True) self.paddle = 0 self.ball = 0 self.c.program[0] = 2 def display_field(self, field, result): for x, y, t in grouper(3, result): if x == -1 and y == 0: self.score = t else: field[y][x] = self.tiles[t] if t == 3: self.paddle = x if t == 4: self.ball = x print('SCORE: {}'.format(self.score)) for line in field: print(''.join(line)) def run(self): while True: try: self.c.run_software() except ValueError: clear() result = self.c.outputs self.c.outputs = [] self.display_field(self.field, result) self.c.inputs.append(self.move_paddle()) if self.c.terminated: clear() result = self.c.outputs self.c.outputs = [] self.display_field(self.field, result) self.c.inputs.append(self.move_paddle()) break def move_paddle(self): if self.paddle > self.ball: return -1 elif self.paddle < self.ball: return 1 return 0
from copy import deepcopy from advents_of_code.common import Computer with open('day15.txt') as data: program = list(map(int, data.read().split(','))) c = Computer(program, wait_for_input=True) grid = [[0] * 50 for i in range(50)] def comp_io(inp, computer): computer.inputs.append(inp) computer.run_software() return computer.outputs.pop() def search(x, y, direction=None, computer=None): print('visiting %d,%d' % (x, y)) if grid[y][x] == 2: print('found at %d,%d' % (x, y)) return True elif grid[y][x] == 1: print('wall at %d,%d' % (x, y)) return False elif grid[y][x] == 3: print('visited at %d,%d' % (x, y)) return False