Ejemplo n.º 1
0
def solve2():
    opcodes[0] = "2"
    intCode = IntCode(opcodes)
    intCode.running = True
    input = 0
    score = 0
    tiles = defaultdict(list)
    paddle = ball = False

    while intCode.running:
        x = intCode.run(input)
        y = intCode.run(input)
        id = intCode.run(input)
        if x == -1 and y == 0:
            score = id
        else:
            if id == 3:
                paddle = True
            elif id == 4:
                ball = True
            elif id == 0:
                for i in range(5):
                    if (x, y) in tiles[i]:
                        tiles[i].remove((x, y))
                        if i == 3: paddle = False
                        if i == 4: ball = False
            tiles[id].append((x, y))

            if paddle and ball:
                input = 0
                if tiles[3][0][0] < tiles[4][0][0]:
                    input = 1
                elif tiles[3][0][0] > tiles[4][0][0]:
                    input = -1
    print(score)
Ejemplo n.º 2
0
def solve1():
    intCode = IntCode(opcodes)
    intCode.running = True
    c = 0
    while intCode.running:
        x = intCode.run(0)
        y = intCode.run(0)
        id = intCode.run(0)
        if id == 2:
            c += 1
    print(c)
Ejemplo n.º 3
0
def paint2():
    intComputer = IntCode(opcodes.split(','))
    panel = defaultdict(int)

    d = 0
    p = (0,0)
    panel[p] = 1

    intComputer.running = True

    while intComputer.running:
        color = intComputer.run(panel[p])
        direction = intComputer.run(panel[p])

        if not intComputer.running:
            break

        panel[p] = color
        
        d = turn(d, direction)
        p = move(p, d)

    return panel