return c # Read program from stdin prog = [] for i in map(int, input('').split(',')): prog.append(i) # Create queues, 0 for input, 1 for output queues = [] for _ in range(2): dq = deque() queues.append(dq) # Create and connect machine m = Intmachine('d11', prog, queues[0], queues[1]) queues[0].clear() m.reset() # Part 2, put color 1 at rx, ry before start. # For part 1, comment out 2 rows below. paintcoords.append((rx, ry)) paintcols.append(1) running = True while running: # push input c = color(rx, ry) m.push(c) while len(m.oq) < 2 and running:
# Use intmachine from ../common import sys sys.path.insert(0, '../common') from intmachine import Intmachine # Read program from stdin prog = [] for i in map(int, input('').split(',')): prog.append(i) # Create queues queues = [] for _ in range(2): dq = deque() queues.append(dq) # Create and connect machines m = Intmachine('d9', prog, queues[0], queues[1]) m.reset() # push single input # task 1, push 1 # m.push(1) # task 2, push 2 m.push(2) while m.do_op(): pass # print output queue while len(m.oq) > 0: print(m.pop())
for i in map(int, line.split(',')): prog.append(i) # Create queues queues = [] for _ in range(2): dq = deque() queues.append(dq) # Dimensions = 50 x 50 width = 50 heigth = 50 board = np.zeros((heigth, width), dtype = np.int) # Create and connect machines m = Intmachine('d19', prog, queues[0], queues[1]) # Fill board and count ones for y in range(heigth): for x in range(width): board[(y, x)] = get_xy(x, y) dump_board() print('part 1:', len(get_yx_list(1))) # Get approximation of slopes around x = 1000 x = 1000 k1 = 0.4 k2 = 0.7 lasty1, lasty2 = get_y1y2(x) k1 = lasty1 / x k2 = lasty2 / x # Adjust range until it works for x in range(1000, 1020):
# Read program from input.txt with open('input.txt') as f: line = f.readline() prog = [] for i in map(int, line.split(',')): prog.append(i) # Create queues queues = [] for _ in range(2): dq = deque() queues.append(dq) # Create and connect machines m = Intmachine('d17', prog, queues[0], queues[1]) m.reset() while m.do_op(): pass # get output data output = '' while len(m.oq) > 0: output += chr(m.pop()) # Dimensions = 47 x 65 width = 47 heigth = 65 board = np.array([0] * width * heigth, dtype=np.int) ytab = np.array([0] * heigth, dtype=np.int)
# Read program from input.txt with open('input.txt') as f: line = f.readline() prog = [] for i in map(int, line.split(',')): prog.append(i) # Create queues queues = [] for _ in range(2): dq = deque() queues.append(dq) # Create and connect machines m = Intmachine('d17', prog, queues[0], queues[1]) m.reset() # Push all data to input queue for c in data: m.push(ord(c)) # Write 2 to position 0 m.poke(0, 2) while m.do_op(): # Write data as it becomes available. # But don't write last value in queue. while len(m.oq) > 1: sys.stdout.write(chr(m.pop()))
#!/usr/bin/env python3 # Solution refactored to use Intmachine in ../common import sys sys.path.insert(0,'../common') from intmachine import Intmachine from collections import deque prog = [] for i in map(int, open(sys.argv[1]).readline().split(',')): prog.append(i) # Create input/output queue dqi = deque() dqo = deque() # Part 1, append 1. Change to 5 for part 2. dqi.appendleft(1) # Create machine and run it machine = Intmachine('day5', prog, dqi, dqo) while machine.do_op(): pass machine.dump_mem() # Print output queue while len(dqo) > 0: print(dqo.pop())
sys.path.insert(0, '../common') from intmachine import Intmachine # Read program from stdin prog = [] for i in map(int, input('').split(',')): prog.append(i) # 0 for input, 1 for output queues = [] for _ in range(2): dq = deque() queues.append(dq) # Create and connect machine m = Intmachine('d13', prog, queues[0], queues[1]) minx = 10000 maxx = 0 miny = 10000 maxy = 0 # part 1, don't play the game, only add blocks blocks = [] def do_game(x, y, tile): global minx, maxx, miny, maxy if x < minx: minx = x if y < miny: miny = y