Esempio n. 1
0
def main():
    with open("dec9/input.txt", "r") as file:
        memory = list(map(int, file.read().split(",")))

    ic = IntCode(memory, inp=[2])
    ic.start()
    return ic.out[0]
Esempio n. 2
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
Esempio n. 3
0
def main():
    with open("dec7/input.txt", "r") as file:
        memory = list(map(int, file.read().split(",")))
    m = 0
    for p in itertools.permutations(list(range(5))):
        index = 0
        currinput = [0]
        a, b, c, d, e = p
        ic_a = IntCode(memory.copy(), inp=[a])
        ic_b = IntCode(memory.copy(), inp=[b])
        ic_c = IntCode(memory.copy(), inp=[c])
        ic_d = IntCode(memory.copy(), inp=[d])
        ic_e = IntCode(memory.copy(), inp=[e])
        ics = [ic_a, ic_b, ic_c, ic_d, ic_e]
        for ic in ics:
            ics[index].inp += currinput
            ics[index].start()
            currinput = ics[index].popout()
            index = (index + 1) % 5
        ic_a.inp.append(0)
        ic_a.start()
        m = max(m, currinput[0])
    return m
Esempio n. 4
0
import sys, os
sys.path.append(os.getcwd())
from util.intcode import IntCode

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

ic = IntCode(memory)
ic.start()

k = [ic.out[i] for i in range(2, len(ic.out), 3)]

print(k.count(2))
Esempio n. 5
0
done = False
while not done:
    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN and event.key in (
                pygame.K_RIGHT, pygame.K_LEFT, pygame.K_UP, pygame.K_DOWN):
            if event.key == pygame.K_RIGHT:
                direction = 4
            elif event.key == pygame.K_LEFT:
                direction = 3
            elif event.key == pygame.K_UP:
                direction = 1
            else:
                direction = 2

            ic.start(inp=[direction])
            out = ic.out[0]
            ic.out = []
            dx, dy = directions[direction]
            data[(position[0] + dx, position[1] + dy)] = out
            if out != 0:
                position = (position[0] + dx, position[1] + dy)

            img = Image.new("RGB", (maxx - minx + 1, maxy - miny + 1),
                            (192, 192, 192))
            pixels = img.load()
            for k, v in data.items():
                x, y = k
                if k == position:
                    pixels[x - minx, y - miny] = (0, 0, 255)
                elif v == 0:
Esempio n. 6
0
# maxx = 31
# maxy = 13
minx = -28
miny = -24
maxx = 50
maxy = 25

images = []
steps = 0
hue = 0
while True:
    if (x, y) in grid and grid[x, y] != 0:
        color = 1
    else:
        color = 0
    ic.start(inp=[color])
    if len(ic.out) < 2:
        break
    newcolor, direction = ic.out
    ic.out = []
    r, g, b = colorsys.hsv_to_rgb(hue, 1, 1)
    if newcolor == 0:
        grid[x, y] = 0
    else:
        grid[x, y] = (int(255 * r), int(255 * g), int(255 * b))
    hue = (hue + 0.0001) % 1
    if direction == 0:
        d = (d - 1) % 4
    else:
        d = (d + 1) % 4
Esempio n. 7
0
 screen.fill((0, 0, 0))
 keys = pygame.key.get_pressed()
 for event in pygame.event.get():
     if event.type == pygame.KEYDOWN:
         if event.key == pygame.K_RIGHT:
             joystick = 1
         elif event.key == pygame.K_LEFT:
             joystick = -1
     elif event.type == pygame.KEYUP and event.key in (pygame.K_RIGHT,
                                                       pygame.K_LEFT):
         joystick = 0
 # if keys[pygame.K_RIGHT]:
 #     joystick = 1
 # elif keys[pygame.K_LEFT]:
 #     joystick = -1
 ic.start(inp=[joystick])
 if len(ic.out) == 0:
     break
 for i in range(0, len(ic.out), 3):
     x, y, tile = ic.out[i:i + 3]
     if x == -1 and y == 0:
         print("score", tile)
     else:
         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")
 ic.out = []
 screen.blit(pg, (0, 0))
 pygame.display.flip()