示例#1
0
        time.sleep(1 / REFRESH_RATE)

    render_scene(screen, current_location, maze_map)
    screen.addstr(0, 0, ('{:^' + str(NX) + 's}').format('FOUND THE THING!'))
    screen.getch()


if __name__ == '__main__':

    assert destination_coordinate((0, 0), NORTH) == (0, 1)
    assert destination_coordinate((0, 0), SOUTH) == (0, -1)
    assert destination_coordinate((0, 0), EAST) == (1, 0)
    assert destination_coordinate((0, 0), WEST) == (-1, 0)

    test_history = {(1, 0): 1, (-1, 0): 2, (0, 1): 3, (0, -1): 4}
    assert get_next_direction((0, 0), test_history) == EAST

    test_history = {(1, 0): 1, (-1, 0): 1, (0, 1): 1, (0, -1): 4}
    assert get_next_direction((0, 0), test_history) != SOUTH

    # display_solution = False
    # if len(sys.argv) > 1:
    #     if sys.argv[1] == '1':
    #         display_solution = True

    program = read_program('./inputs/day15.txt')

    # if display_solution:
    curses.wrapper(main_rendered, program)
示例#2
0
def main(screen: Any, bot_player: bool):

    program = read_program('./inputs/day13.txt')
    cabinet = ArcadeCabinet(screen, program)
    cabinet.game_loop(bot_player=bot_player)
示例#3
0
    assert run_amplifiers(test_program, 0, [4, 3, 2, 1, 0]) == 43210

    test_program = [3,23,3,24,1002,24,10,24,1002,23,-1,23,101,5,23,23,1,24,23,23,4,23,99,0,0]
    assert run_amplifiers(test_program, 0, [0, 1, 2, 3, 4]) == 54321

    test_program = [3,31,3,32,1002,32,10,32,1001,31,-2,31,1007,31,0,33,1002,33,7,33,1,33,31,31,1,32,31,31,4,31,99,0,0,0]
    assert run_amplifiers(test_program, 0, [1, 0, 4, 3, 2]) == 65210


    test_program = [3,26,1001,26,-4,26,3,27,1002,27,2,27,1,27,26,27,4,27,1001,28,-1,28,1005,28,6,99,0,0,5]
    assert run_amplifiers_with_feedback(test_program, 0, [9,8,7,6,5]) == 139629729

    test_program = [3,52,1001,52,-5,52,3,53,1,52,56,54,1007,54,5,55,1005,55,26,1001,54,-5,54,1105,1,12,1,53,54,53,1008,54,0,55,1001,55,1,55,2,53,55,53,4,53,1001,56,-1,56,1005,56,6,99,0,0,0,0,10]
    assert run_amplifiers_with_feedback(test_program, 0, [9,7,8,5,6]) == 18216

    amplifier_program = read_program('./inputs/day07.txt')
    
    results = []
    for phases in permutations(range(5)):

        amp_output = run_amplifiers(amplifier_program, 0, phases)

        results.append((phases, amp_output))

    max_output_phases = max(results, key=lambda x: x[1])

    print(f'Max output: {str(max_output_phases[1])} from phases {str(max_output_phases[0])}')

    results = []
    for phases in permutations(range(5, 10)):
示例#4
0
def run():
    program = read_program('./inputs/day15.txt')

    # if display_solution:
    curses.wrapper(main_rendered, program)
示例#5
0
    assert output[0] == 204
    test_program = [109, 1, 3, 3, 204, 2, 99]  # input
    test_program = [109, 1, 203, 2, 204, 2, 99]  # input
    test_computer = IntcodeComputer(test_program)
    output = test_computer.run(234)
    print(test_computer.memory)
    assert output[0] == 234

    test_program = [1102,34915192,34915192,7,4,7,99,0]
    test_computer = IntcodeComputer(test_program)
    output = test_computer.run()[0]
    assert len(str(output)) == 16

    test_program = [104,1125899906842624,99]
    test_computer = IntcodeComputer(test_program)
    output = test_computer.run()[0]
    assert output == test_program[1]

    program = read_program('./inputs/day09.txt')
    computer = IntcodeComputer(program)
    output = computer.run(1)
    assert len(output) == 1

    print(f"BOOST keycode: {output[0]}")

    computer = IntcodeComputer(program)
    output = computer.run(2)
    assert len(output) == 1

    print(f"Distress coordinates: {output[0]}")