コード例 #1
0
ファイル: day11.py プロジェクト: ey3ball/adventofcode2019
 def __init__(self, start_position, program):
     Robot.__init__(self, start_position)
     self.argv = []
     self.interpreter = IntCodeInterpreter(program)
     self.call_program = self.interpreter.run_gen()
     print("ran")
     self.i = 0
コード例 #2
0
class Droid:
    def __init__(self, program):
        self.droid = IntCodeInterpreter(program)
        self.droid_gen = self.droid.run_gen()

    def move(self, direction):
        self.droid.push_input(direction)

    def status(self):
        return next(self.droid_gen)
コード例 #3
0
ファイル: day11.py プロジェクト: ey3ball/adventofcode2019
class IntCodeRobot(Robot):
    def __init__(self, start_position, program):
        Robot.__init__(self, start_position)
        self.argv = []
        self.interpreter = IntCodeInterpreter(program)
        self.call_program = self.interpreter.run_gen()
        print("ran")
        self.i = 0

    def next(self, pixel_value):
        self.i += 1

        self.interpreter.push_input(pixel_value)
        color = next(self.call_program)
        turn = next(self.call_program)

        return (color, turn)
コード例 #4
0
SIZE = 100
scanner = [[" " for x in range(0,SIZE)] for y in range(0, SIZE)]

x_off = int(sys.argv[1])
y_off = int(sys.argv[2])

def show_map(scan):
    for y, line in enumerate(scan):
        for x, obj in enumerate(line):
            sys.stderr.write(obj)
        sys.stderr.write("\n")
    sys.stderr.write("\n")

count = 0
drone = IntCodeInterpreter(program)
drone_gen = drone.run_gen()
for y, line in enumerate(scanner):
    for x, _ in enumerate(line):
        drone.reset()
        drone.push_input(x+x_off)
        drone.push_input(y+y_off)

        status = next(drone_gen)

        if status == 0:
            scanner[y][x] = "."
        else:
            scanner[y][x] = "#"
            count += 1
コード例 #5
0
#!/usr/bin/env python3

from intcode import IntCodeInterpreter
import sys
import math

SCAFFOLD = "#"
VOID = "."
INTERSECT = "O"

with open("day17.txt", "r") as f:
    program = f.readline().strip()

droid = IntCodeInterpreter(program)
droid_gen = droid.run_gen()

cameras = []
line = []
for output in droid_gen:
    if output == 10:
        if line != []:
            cameras.append(line)
            line = []
    else:
        line.append(output)
    sys.stderr.write(chr(output))

HEIGHT = len(cameras)
WIDTH = len(cameras[0])
print(HEIGHT)
コード例 #6
0
ファイル: day17_1.py プロジェクト: ey3ball/adventofcode2019
#!/usr/bin/env python3

from intcode import IntCodeInterpreter
import sys
import math

SCAFFOLD = "#"
VOID = "."
INTERSECT = "O"

with open("day17.txt", "r") as f:
    program = f.readline().strip()

droid = IntCodeInterpreter(program)
droid_gen = droid.run_gen()

cameras = []
line = []
for output in droid_gen:
    if output == 10:
        if line != []:
            cameras.append(line)
            line = []
    else:
        line.append(output)
    sys.stderr.write(chr(output))

HEIGHT = len(cameras)
WIDTH = len(cameras[0])
print(HEIGHT)
コード例 #7
0
 def __init__(self, program):
     self.droid = IntCodeInterpreter(program)
     self.droid_gen = self.droid.run_gen()
コード例 #8
0
#!/usr/bin/env python3

from intcode import IntCodeInterpreter
import sys

PCK_ADDR = 0
PCK_X = 1
PCK_Y = 2

with open("day23.txt", "r") as f:
    program = f.readline().strip()

_nics = [IntCodeInterpreter(program) for i in range(0, 50)]

nics = []
for i, nic in enumerate(_nics):
    nic.push_input(i)
    nic.__dict__.update({'i': i})
    nics.append((nic, nic.run_gen()))

old_nat = [-1, -1]
nat = []
delivered = []

while True:
    idle = True
    for nic, nic_gen in nics:
        packet = []
       
        starved = False
        for i in range(0,3):
コード例 #9
0
Since the output from the game produces threee consecutive values at a time, I
decided it would be a good opportunity to give itertools.groupby a try.

Sadly groupby in order to group inputs by 3, groupby implementation has to
access the 4th element in the following loop :

for _, group in groupby(enumerate(gen), key=lambda e: e[0] // 3):

This means my loop is always one move behind which is one I ended up
reverse-engineering the ball movement in order to predict its next position ...
"""

with open("day13.txt", "r") as f:
    program = f.readline().strip()

interpreter = IntCodeInterpreter(program)
interpreter.mem[0] = 2
gen = interpreter.run_gen()

screen_ok = False

WALL = 1
BLOCK = 2
CURSOR = 3
BALL = 4
PADDLE = 3

def wall(tile):
    if tile == WALL or tile == BLOCK:
        return True
    else:
コード例 #10
0
def check_pos(x,y):
    drone = IntCodeInterpreter(program)
    drone_gen = drone.run_gen()
    drone.push_input(x)
    drone.push_input(y)
    return next(drone_gen)