Пример #1
0
def test(x, y):
    if x < 0 or y < 0:
        return False
    ic = IntCode(memory.copy())
    ic.inp += [x, y]
    ic.start()
    out = ic.popout()
    return out[0] == 1
Пример #2
0
pixels = img.load()
raw_str = img2.tobytes("raw", "RGB")
pg = pygame.image.fromstring(raw_str, (440, 240), "RGB")
while True:
    screen.fill((0, 0, 0))
    if ballpos < paddlepos:
        joystick = -1
    elif ballpos > paddlepos:
        joystick = 1
    else:
        joystick = 0
    ic.inp.append(joystick)
    ic.start()
    if len(ic.out) == 0:
        break
    out = ic.popout()
    for i in range(0, len(out), 3):
        x, y, tile = out[i:i + 3]
        if x == -1 and y == 0:
            print("score", tile)
        else:
            if tile == 3:
                paddlepos = x
            elif tile == 4:
                ballpos = x
            pixels[x, y] = colors[tile]
    img2 = img.resize((440, 240))
    images.append(img)
    raw_str = img2.tobytes("raw", "RGB")
    pg = pygame.image.fromstring(raw_str, (440, 240), "RGB")
    screen.blit(pg, (0, 0))
Пример #3
0
import sys, os
sys.path.append(os.getcwd())
from util.intcode import IntCode

with open("dec21/input.txt", "r") as file:
    memory = list(map(int, file.read().split(",")))

instructions = "NOT C J\nAND D J\nNOT A T\nOR T J\nWALK"
ic = IntCode(memory)
ic.inp += list(map(ord, list(instructions)))
ic.start()

print(ic.popout())
Пример #4
0
ic = IntCode(field)
grid = {(0, 0): 1}
x, y = 0, 0
d = 0

while True:
    if (x, y) in grid:
        color = grid[x, y]
    else:
        color = 0
    ic.inp.append(color)
    ic.start()
    if len(ic.out) < 2:
        break
    newcolor, direction = ic.popout()
    grid[x, y] = newcolor
    if direction == 0:
        d = (d - 1) % 4
    else:
        d = (d + 1) % 4

    if d == 0: y -= 1
    elif d == 1: x += 1
    elif d == 2: y += 1
    else: x -= 1

minx = min(g[0] for g in grid.keys())
miny = min(g[1] for g in grid.keys())
maxx = max(g[0] for g in grid.keys())
maxy = max(g[1] for g in grid.keys())
Пример #5
0
import sys, os
sys.path.append(os.getcwd())
from util.intcode import IntCode

with open("dec21/input.txt", "r") as file:
    memory = list(map(int, file.read().split(",")))

with open("dec21/instructions2.txt", "r") as ins:
    instructions = ins.read()

ic = IntCode(memory)
ic.inp += list(map(ord, list(instructions)))
ic.start()

# print(ic.popout())
print(ic.popout()[-1])
Пример #6
0
import sys, os
sys.path.append(os.getcwd())
from util.intcode import IntCode

with open("dec17/input.txt", "r") as file:
    memory = list(map(int, file.read().split(",")))

ic = IntCode(memory)
ic.start()
string = "".join(chr(k) for k in ic.popout())
lines = string.strip().split("\n")
print(lines)
total = 0
for x in range(1, len(lines[0]) - 2):
    for y in range(1, len(lines) - 2):
        if lines[y][x] == "#" and lines[y - 1][x] == "#" and lines[
                y + 1][x] == "#" and lines[y][x +
                                              1] == "#" and lines[y][x -
                                                                     1] == "#":
            total += y * x
print(total)