Ejemplo n.º 1
0
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:
        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:
Ejemplo n.º 2
0
# 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())
Ejemplo n.º 3
0
#!/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())