# 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())
# 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: running = m.do_op() # Got two outputs if len(m.oq) == 2: c = m.pop() d = m.pop() paint_move(c, d) # part 1 print(len(paintcoords)) # get dimensions minx = 10000 maxx = -10000 miny = 10000 maxy = -10000 for t in paintcoords: x = t[0] y = t[1] if x < minx:
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())) # Write anything left in output queue while len(m.oq) > 1: sys.stdout.write(chr(m.pop())) print(m.pop())
# 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) moves = { 'up': np.array([0, -1], dtype=np.int), 'down': np.array([0, 1], dtype=np.int), 'left': np.array([-1, 0], dtype=np.int), 'right': np.array([1, 0], dtype=np.int) } # Store idx values in board
if y < miny: miny = y if x > maxx: maxx = x if y > maxy: maxy = y # 0 = empty # 1 = wall # 2 = block # 3 = paddle # 4 = ball if tile == 2: # add block if not (x, y) in blocks: blocks.append((x, y)) running = True while running: while len(queues[1]) < 3 and running: running = m.do_op() if running: # Got three outputs x = m.pop() y = m.pop() tile = m.pop() do_game(x, y, tile) print(minx, maxx, miny, maxy) print(len(blocks))