Esempio n. 1
0
def run_program(computer: Computer) -> bool:
    try:
        computer.run()
        return True
    except Exception as e:
        print(str(e))
        return False
def find_phase_sequence(registers: List[int],
                        amplifiers: int) -> Tuple[Tuple[int, ...], int]:
    # Python libraries help me cheat in generating permutations :D
    sequence_scores = {x: None for x in permutations(range(amplifiers))}

    for curr_sequence in sequence_scores.keys():
        input_val = 0
        for amp_number in range(amplifiers):
            comp = Computer(copy_registers(registers),
                            inputs=[curr_sequence[amp_number], input_val])
            outputs = comp.run()
            input_val = outputs[0]
        sequence_scores[curr_sequence] = input_val

    return max([(k, v) for k, v in sequence_scores.items()],
               key=lambda x: x[1])