Ejemplo n.º 1
0
#!python
# https://adventofcode.com/2019/day/9

from ICProgram import ICProgram as ICP

lines = []
with open('input.txt', 'r') as f:
    lines = f.readlines()

program = [int(c) for c in lines[0].split(',')]

machine = ICP()
machine.loadProgram(program)
machine.feedInput(1)
machine.start()
while (machine.waitForOutput()):
    print(machine.getOutput())  # Part 1: 2775723069

machine.stop()
machine.feedInput(2)
machine.start()
while (machine.waitForOutput()):
    print(machine.getOutput())  # Part 2: 49115
Ejemplo n.º 2
0
                print('□', end='')
            elif (tile == 3):
                print('─', end='')
            elif (tile == 4):
                print('○', end='')
        print('')
    print('{:0>7}'.format(score))
    time.sleep(0.1)


lines = []
with open('input.txt', 'r') as f:
    lines = [int(c) for c in f.readlines()[0].strip().split(',')]

tiles = {}
game = ICP()
game.loadProgram(lines)
game.start()
while (game.waitForOutput()):
    x = game.getOutput()
    y = game.getOutput()
    tileId = game.getOutput()
    if (x == -1 and y == 0):
        # Score
        score = tileId
        continue
    tiles[(x, y)] = tileId
if (not VISUALIATION):
    print(len(list(filter(lambda c: c == 2, tiles.values()))))  # Part 1: 372
maxX = max(x for x, y in tiles.keys())
maxY = max(y for x, y in tiles.keys())
Ejemplo n.º 3
0
#!python
# https://adventofcode.com/2019/day/23
from ICProgram import ICProgram as ICP
import sys

nat = None
listY = []

program = []
with open('input.txt', 'r') as f:
	program = f.readlines()[0].strip().split(',')

computers = []
for i in range(50):
	c = ICP()
	c.loadProgram(program)
	c.feedInput(i)
	computers.append(c)

for c in computers:
	c.start()

while(1):
	netIdle = True
	for i in range(len(computers)):
		c = computers[i]
		netIdle &= c.isIdle()
		if(dest := c.getOutput(False)):
			X = c.getOutput()
			Y = c.getOutput()
			# print('From {} to {} X={} Y={}'.format(i, dest, X, Y))
Ejemplo n.º 4
0
#!python
# https://adventofcode.com/2019/day/25
from ICProgram import ICProgram as ICP
from threading import Thread

def listen(icp):
	while(icp.waitForOutput()):
		print(chr(icp.getOutput()), end='')

program = []
with open('input.txt', 'r') as f:
	program = f.readlines()[0].strip().split(',')

droid = ICP()
droid.loadProgram(program)
droid.start()

Thread(target=listen, args=(droid,), daemon=True).start()

while(1):
	for c in input():
		droid.feedInput(ord(c))
	droid.feedInput(10)
Ejemplo n.º 5
0

def inspectCoord(x, y):
    drone.start()
    drone.feedInput(x)
    drone.feedInput(y)
    a = drone.getOutput()
    drone.stop()
    return a


program = []
with open('input.txt', 'r') as f:
    program = f.readlines()[0].strip().split(',')

drone = ICP()
drone.loadProgram(program)
affected = 0
for y in range(50):
    for x in range(50):
        a = inspectCoord(x, y)
        # print(a, end='')
        affected += a
    # print('')

print(affected)  # Part 1: 171

x, y = 0, 10

while (1):
    while (inspectCoord(x, y) == 0):
Ejemplo n.º 6
0
            except IndexError:
                return False
        return True
    return False


def alignParam(x, y):
    return x * y


program = []
with open('input.txt', 'r') as f:
    program = f.readlines()[0].strip().split(',')

grid = [[46 for x in range(77)] for y in range(41)]
robot = ICP()
robot.loadProgram(program)
robot.start()
x, y = 0, 0
while (robot.waitForOutput()):
    # print(chr(robot.getOutput()), end='')
    c = robot.getOutput()
    if (c == 10):
        y += 1
        x = 0
    else:
        grid[y][x] = c
        x += 1

acc = 0
for y in range(len(grid)):
Ejemplo n.º 7
0
#!python
# https://adventofcode.com/2019/day/21
from ICProgram import ICProgram as ICP

program = []
with open('input.txt', 'r') as f:
    program = f.readlines()[0].strip().split(',')
springdroid = ICP()
springdroid.loadProgram(program)
springdroid.start()
commandWalk = \
'''NOT A J
NOT C T
AND D T
OR T J
NOT B T
AND D T
OR T J
WALK
'''
for c in commandWalk:
    springdroid.feedInput(ord(c))
while (springdroid.waitForOutput()):
    try:
        print(chr(c := (springdroid.getOutput())), end='')
    except:
        print(c)  # Part 1: 19357507
springdroid.stop()
springdroid.start()
commandRun = \
'''RUN
Ejemplo n.º 8
0

def turn(angle):
    global pointing
    # angle = 0: Turn left
    # angle = 1: Turn right
    pointing = (pointing + (1 if angle == 1 else -1)) % 4


def move():
    global position
    position = (position[0] + direction[pointing][0],
                position[1] + direction[pointing][1])


brain = ICP()
brain.loadProgram(lines)
brain.feedInput(visitedCells[position])
brain.start()
while (brain.waitForOutput()):
    newColor = brain.getOutput()
    visitedCells[position] = newColor
    angle = brain.getOutput()
    turn(angle)
    move()
    standingColor = visitedCells[position] if position in visitedCells.keys(
    ) else 0
    brain.feedInput(standingColor)
print(len(visitedCells.keys()))  # Part 1: 2539

minx = min(x for x, y in visitedCells.keys())