Example #1
0
    def test_jump_pos(self):
        runner = create_runner("test/jump_pos.txt", 1)
        runner.run()
        self.assertEquals(1, runner.output_value())

        runner = create_runner("test/jump_pos.txt", 0)
        runner.run()
        self.assertEquals(0, runner.output_value())
Example #2
0
    def test_large_numbers(self):
        runner = create_runner("test/large_numbers.txt")
        runner.run()
        self.assertEquals(1219070632396864, runner.output_value())

        runner = create_runner("test/large_numbers2.txt")
        runner.run()
        self.assertEquals(1125899906842624, runner.output_value())
Example #3
0
    def test_less_than_8_pos_mode(self):
        runner = create_runner("test/less_than_8_pos_mode.txt", 1)
        runner.run()
        self.assertEquals(1, runner.output_value())

        runner = create_runner("test/less_than_8_pos_mode.txt", 8)
        runner.run()
        self.assertEquals(0, runner.output_value())
Example #4
0
    def test_rel_base(self):
        runner = create_runner("test/rel_base.txt")
        runner.run()
        self.assertEquals(19, runner._rel_base)

        runner = create_runner("test/rel_base2.txt")
        runner.run()
        self.assertEquals(31337, runner.output_value())
Example #5
0
    def test_equal_8_int_mode(self):
        runner = create_runner("test/equal_8_int_mode.txt", 8)
        runner.run()
        self.assertEquals(1, runner.output_value())

        runner = create_runner("test/equal_8_int_mode.txt", 1)
        runner.run()
        self.assertEquals(0, runner.output_value())
Example #6
0
def main(input):
    test()

    runner = intcode.create_runner(input, 0)
    grid = paint(runner)
    print(len(grid.keys()))

    runner = intcode.create_runner(input, 1)
    grid = paint(runner)
    print_grid(grid)
Example #7
0
    def test_expand_memory(self):
        runner = create_runner("test/expand_memory_store.txt")
        runner.run()
        self.assertEquals(8, runner.output_value())
        self.assertEquals(11, len(runner._program))

        runner = create_runner("test/expand_memory_load.txt")
        runner.run()
        self.assertEquals(81, runner.output_value())
        self.assertEquals(101, len(runner._program))
Example #8
0
    def test_breakpoint_on_opcodes(self):
        runner = create_runner("test/io.txt", 1)
        ec = runner.run()
        self.assertEquals(99, ec)

        runner = create_runner("test/io.txt", 1)
        runner.add_breakpoint_opcode(4)
        runner.add_breakpoint_opcode(3)
        ec = runner.run()
        self.assertEquals(3, ec)
        ec = runner.run()
        self.assertEquals(4, ec)
        self.assertEquals(1, runner.output_value())
Example #9
0
def main(input):
    runner = intcode.create_runner(input)
    grid = create_game_grid(runner)
    x_max, y_max = grid_dimensions(grid)
    print_grid(grid, x_max, y_max)

    block_tile_count = 0
    for k in grid.values():
        if k == 2:
            block_tile_count += 1
    print(block_tile_count)

    runner = intcode.create_runner(input)
    score = run_game(runner, grid, x_max, y_max)
    print(score)
Example #10
0
 def test_output_value(self):
     runner = create_runner("test/equal_8_pos_mode.txt", 8)
     try:
         val = runner.output_value()
         self.fail("Should raise NotInitializedException")
     except NotInitializedException:
         pass
Example #11
0
 def test_reset_input_offet(self):
     runner = create_runner("test/io2.txt", 1, 2)
     runner.run()
     out = runner.output_value()
     runner.set_input_values(2, 1)
     runner._pc = 0
     runner.run(True)
     self.assertEquals(2, runner.output_value())
Example #12
0
def main(input):
    runner = intcode.create_runner(input)

    grid = get_grid(runner)
    intersections = get_intersections(grid)
    print(sum([pos[0] * pos[1] for pos in intersections]))

    # https://docs.google.com/spreadsheets/d/15wLqapfZMMDCPygSJAw0JPA8LX6mrJzCc-aFj2biwJY/edit?folder=0AK2tILtqsQc4Uk9PVA#gid=862776920
    # seq = 'A,B,A,C,B,C,A,C,B,C'
    # A = 'L,8,R,10,L,10'
    # B = 'R,10,L,8,L8,L,10'
    # C = 'L,4,L,6,L8,L8'

    path = get_path(grid)
    parts = find_parts(path)
    runner = intcode.create_runner(input)
    find_robots(clean(parts), runner)
Example #13
0
def run_sequence(input_file, sequence):
    last_output = 0
    for phase in sequence:
        runner = intcode.create_runner(input_file, phase, last_output)
        runner.run()
        last_output = runner.output_value()

    return last_output
Example #14
0
    def test_quine(self):
        runner = create_runner("test/quine.txt")
        output = []
        while True:
            if runner.run(True) == 99:
                break
            output.append(runner.output_value())

        self.assertEquals(output, runner._program[:16])
Example #15
0
def init(f):
    computers = []
    for address in range(50):
        runner = intcode.create_runner(f, address, -1)
        runner.add_breakpoint_opcode(4)
        runner.add_breakpoint_opcode(5)
        computers.append(runner)

    return computers
Example #16
0
def part_two(f):
    runner = intcode.create_runner(f)
    code = """NOT A J
NOT C T
AND D T
AND H T
OR T J
NOT B T
AND D T
OR T J
RUN
"""
    run_springscript(f, code)
Example #17
0
def run_springscript(f, code):
    runner = intcode.create_runner(f)
    runner.set_input_values(*ascii(code))

    while True:
        ec = runner.run(True)
        if ec == 99:
            break

        val = runner.output_value()
        if val < 128:
            print(chr(val), end='')
        else:
            print(val)

    print()
Example #18
0
def part_one(f):
    runner = intcode.create_runner(f)

    doors = []
    items = []
    moves = []

    banned_items = set([
        'molten lava', 'infinite loop', 'photons', 'giant electromagnet',
        'escape pod'
    ])

    runner, doors, items, inv, room = run(runner, doors, items)
    while True:
        print('room', room)
        print('moves', moves)
        print("$ ", end='')

        str = input()
        str = str.strip()
        str = SHORTCUTS.get(str, str)

        if str == 'gather':
            runner, doors, items, room = gather(runner, doors, items, room,
                                                banned_items)
            continue

        if str == 'bruteforce':
            runner, doors, items, room = bruteforce(runner, doors, room,
                                                    'south')
            continue

        if str.startswith('warp'):
            destination = str[5:]
            runner, doors, items, room = warp(runner, doors, room, destination)
            continue

        if str in doors and "ejected" not in str:
            if len(moves) > 0 and moves[-1] == OPPOSITES[str]:
                moves.pop()
            else:
                moves.append(str)

        runner.set_input_values(*ascii(str + '\n'))
        runner, doors, items, inv, room = run(runner, doors, items)

    print()
Example #19
0
def main(f):
    f = intcode.create_runner(f)
    test_beam(f, 50, True)

    # guess starting pos
    y = 1000
    size = 100
    x = 0
    while True:
        x = find_first_1(f, y, x)
        if hit(f, x, y, size):
            print(
                "hit sized square at",
                x,
            )
            print(x * 10000 + (y - size + 1))
            break
        y += 1
Example #20
0
def run_pumped_sequence(input_file, sequence):
    runners = {}
    last_output = 0
    last_e_output = 0
    while (True):
        for i in range(0, 5):
            runner = runners.get(i)
            if runner is None:
                runner = intcode.create_runner(input_file, sequence[i],
                                               last_output)
                runners[i] = runner
            runner._input_values[1] = last_output

            opcode = runner.run(True)
            last_output = runner.output_value()

            if i == 4:
                last_e_output = last_output

            if opcode == 99:
                return last_e_output
Example #21
0
 def test_rel_add(self):
     runner = create_runner("test/rel_mul.txt")
     runner.run()
     self.assertEquals(222020, runner.output_value())
Example #22
0
def main(input, value):
    runner = intcode.create_runner(input, int(value))
    runner.run()
    print(runner.output_value())
Example #23
0
 def test_rel_jnz(self):
     runner = create_runner("test/rel_jnz.txt")
     runner.run()
     self.assertEquals(31337, runner.output_value())
Example #24
0
def main(f):
    runner = intcode.create_runner(f)
    grid = {}

    backtrack_explore(runner, grid)
    spread(grid)
Example #25
0
 def test_rel_less_than(self):
     runner = create_runner("test/rel_lt.txt")
     runner.run()
     self.assertEquals(1, runner.output_value())
Example #26
0
 def test_io(self):
     runner = create_runner("test/io.txt", 31337)
     runner.run()
     self.assertEquals(31337, runner.output_value())
Example #27
0
 def test_rel_store(self):
     runner = create_runner("test/rel_store.txt", 31337)
     runner.run()
     self.assertEquals(31337, runner.output_value())