Ejemplo n.º 1
0
def test_larger_input(test_input, expected):
    computer = Computer([
        3, 21, 1008, 21, 8, 20, 1005, 20, 22, 107, 8, 21, 20, 1006, 20, 31,
        1106, 0, 36, 98, 0, 0, 1002, 21, 125, 20, 4, 20, 1105, 1, 46, 104, 999,
        1105, 1, 46, 1101, 1000, 1, 20, 4, 20, 1105, 1, 46, 98, 99
    ])

    assert computer.compute(test_input) == expected
Ejemplo n.º 2
0
def main():
    computer = IntCodeComputer(puzzle_input)
    first_painting = HullPainting(computer)
    first_painting.paint()
    print(len(first_painting.visited_positions))

    computer.reset()
    second_painting = HullPainting(computer, first_color=1)
    second_painting.paint()
    second_painting.show_painting()
Ejemplo n.º 3
0
def part_2():
    ball_x = paddle_x = None
    computer = IntCodeComputer(instructions, lambda: (ball_x > paddle_x) - (ball_x < paddle_x))
    computer.memory[0] = 2

    points = 0
    while not computer.done:
        for x, y, tile in chunk(computer.compute(return_on_output=True), 3):
            paddle_x = x if tile == 3 else paddle_x
            ball_x = x if tile == 4 else ball_x
            points = tile if (x, y) == (-1, 0) else points
        return points
Ejemplo n.º 4
0
def test_input(test_input, expected):
    computer = Computer([3, 9, 8, 9, 10, 9, 4, 9, 99, -1, 8])
    assert computer.compute(test_input) == expected
Ejemplo n.º 5
0
def test_add_and_multiply(test_input, expected):
    computer = Computer(test_input)
    computer.compute()
    assert computer.memory == expected
Ejemplo n.º 6
0
from Computer import IntCodeComputer as Computer
from puzzle_input import puzzle_input

if __name__ == '__main__':
    computer = Computer(puzzle_input)
    computer.compute(1, silence=False)

    computer.reset()
    computer.compute(2, silence=False)
Ejemplo n.º 7
0
def part_1():
    computer = IntCodeComputer(instructions)
    total = sum(1 for _, _, tile in chunk(computer.compute(return_on_output=True), 3) if tile == 2)
    return total