def ans(): for noun in range(100): for verb in range(100): data = input[:] data[1], data[2] = noun, verb intcode(data) if data[0] == 19690720: return noun, verb return "No answer found..."
def __init__(self, program): self.map = {(0, 0): EMPTY} self.location = (0, 0) self.program = intcode(program) self.program.send(None) # Initialize self.target_found = False self.counter = 0
def __init__(self, routine, A, B, C, live_feed): self.routine = routine self.functions = [A, B, C] self.live_feed = live_feed self.program = intcode(aft) # self.program.send(None) self.buffer = [] self.grid = [['.' for _ in range(W)] for __ in range(H)] self.dust = 0
def __init__(self, game_input): self.board = [[0 for _ in range(WIDTH)] for __ in range(HEIGHT)] self.game = intcode(game_input) self.buffer = [] self.score, self.ball_x, self.paddle_x, self.num_blocks = 0, 0, 0, 341
from common import _intcode as intcode with open('day2_1.txt') as f: data = [int(c) for c in f.readline().strip().split(",")] data[1] = 12 data[2] = 2 intcode(data) print(data[0])
from common import intcode, tadd DIRECTIONS = [(0, 1), (1, 0), (0, -1), (-1, 0)] with open('day11.txt') as f: paint = [int(c) for c in f.readline().strip().split(",")] rob = intcode(paint) rob.send(None) pos, direction = (0, 0), (0, -1) painted = {(0, 0): 1} try: while True: painted[pos] = rob.send(painted.get(pos, 0)) if next(rob) == 0: direction = DIRECTIONS[(DIRECTIONS.index(direction) + 1) % 4] else: direction = DIRECTIONS[(DIRECTIONS.index(direction) - 1) % 4] pos = tadd(pos, direction) next(rob) # advance to next input except StopIteration: pass max_x, max_y = float('-inf'), float('-inf') min_x, min_y = float('inf'), float('inf') for coord in painted: x, y = coord
from common import _intcode as intcode with open('day5_1.txt') as f: TEST = [int(c) for c in f.readline().strip().split(",")] # Part one solved with input 0, part 2 with 5 intcode(TEST, debug=False)
from itertools import permutations from common import intcode with open('day7.txt') as f: acs = [int(c) for c in f.readline().strip().split(",")] # acs = [int(c) for c in "3,15,3,16,1002,16,10,16,1,16,15,15,4,15,99,0,0".split(",")] # acs = [int(c) for c in "3,23,3,24,1002,24,10,24,1002,23,-1,23,101,5,23,23,1,24,23,23,4,23,99,0,0".split(",")] # acs = [int(c) for c in "3,31,3,32,1002,32,10,32,1001,31,-2,31,1007,31,0,33,1002,33,7,33,1,33,31,31,1,32,31,31,4,31,99,0,0,0".split(",")] max_ = 0 for phase in permutations(range(5)): amp_input = 0 for amp in range(5): gen = intcode(acs[:]) gen.send(None) gen.send(phase[amp]) amp_input = gen.send(amp_input) max_ = max(max_, amp_input) print(max_)
from common import intcode, tadd, grid_to_string with open('day17.txt') as f: aft = [int(c) for c in f.readline().strip().split(",")] DIRECTIONS = [(1, 0), (0, 1), (-1, 0), (0, -1)] if __name__ == "__main__": s = ''.join(chr(i) for i in list(intcode(aft))) s = s.rstrip() # remove trailing new lines grid = [[c for c in row] for row in s.split('\n')] intersections = [] for j, row in enumerate(grid): for i, cell in enumerate(row): if cell == "#": try: if all([ grid[y][x] == "#" for x, y in [tadd(d, (i, j)) for d in DIRECTIONS] ]): intersections.append((i, j)) except IndexError: pass print(grid_to_string(grid)) # print(intersections) ans = sum(x * y for x, y in intersections) print(ans) print(len(grid[0]), len(grid))
from itertools import permutations from common import intcode with open('day7.txt') as f: acs = [int(c) for c in f.readline().strip().split(",")] # acs = [int(c) for c in "3,26,1001,26,-4,26,3,27,1002,27,2,27,1,27,26,27,4,27,1001,28,-1,28,1005,28,6,99,0,0,5".split(",")] # acs = [int(c) for c in "3,52,1001,52,-5,52,3,53,1,52,56,54,1007,54,5,55,1005,55,26,1001,54,-5,54,1105,1,12,1,53,54,53,1008,54,0,55,1001,55,1,55,2,53,55,53,4,53,1001,56,-1,56,1005,56,6,99,0,0,0,0,10".split(",")] if __name__ == "__main__": max_ = 0 for phase in permutations(range(5,10)): amps = [intcode(acs[:]) for _ in range(5)] for i, amp in enumerate(amps): amp.send(None) amp.send(phase[i]) amp_input = 0 output = None while output is None: for j, amp in enumerate(amps): try: amp_input = amp.send(amp_input) next(amp) # advance generator to next call for input except: if j == 4: output = amp_input max_ = max(max_, output) print(max_)
from common import intcode with open('day9.txt') as f: boost = [int(c) for c in f.readline().strip().split(",")] # boost = [int(c) for c in "109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99".split(",")] # boost = [int(c) for c in "104,1125899906842624,99".split(",")] # boost = [int(c) for c in "1102,34915192,34915192,7,4,7,99,0".split(",")] gen = intcode(boost, False) gen.send(None) print(gen.send(1)) for out in gen: print(out)
from common import intcode with open('day13.txt') as f: game_input = [int(c) for c in f.readline().strip().split(",")] TILES = { 0: ' ', 1: u"\u25A0", # wall 2: u"\u25A1", # block 3: u"\U0001F3D3", # horizontal paddle 4: u"\u2299" # ball } board = [] game = intcode(game_input) for x in game: y, val = next(game), next(game) if y >= len(board): board.append([]) board[y].append(val) no_blocks = 0 for row in board: s = "" for cell in row: s += TILES[cell] + " " if cell == 2: no_blocks +=1 print(s)
def is_pulled(x, y): program = intcode(program_input) program.send(None) program.send(x) val = program.send(y) return val == 1
from common import intcode, tadd, grid_to_string with open('day19.txt') as f: program_input = [int(c) for c in f.readline().strip().split(",")] if __name__ == "__main__": grid = [] for j in range(50): grid.append([]) for i in range(50): program = intcode(program_input) program.send(None) program.send(i) val = program.send(j) grid[j].append('#' if val == 1 else '.') print(grid_to_string(grid)) print(sum(row.count('#') for row in grid))