Esempio n. 1
0
def part_b(instructions):

    phase_settings = get_phase_settings(True)
    best_score = 0
    for i in range(len(phase_settings)):
        phase_setting = phase_settings[i]

        amp_a, amp_b, amp_c, amp_d, amp_e = Computer(instructions), Computer(
            instructions), Computer(instructions), Computer(
                instructions), Computer(instructions)

        amp_a.input_1 = phase_setting[0]
        amp_a.do_feedback = True
        amp_b.input_1 = phase_setting[1]
        amp_b.do_feedback = True
        amp_c.input_1 = phase_setting[2]
        amp_c.do_feedback = True
        amp_d.input_1 = phase_setting[3]
        amp_d.do_feedback = True
        amp_e.input_1 = phase_setting[4]
        amp_e.do_feedback = True

        initialised = False

        while True:
            amp_a.input_2 = 0 if not initialised else amp_e.output_signal
            amp_a.run()
            initialised = True

            amp_b.input_2 = amp_a.output_signal
            amp_b.run()

            amp_c.input_2 = amp_b.output_signal
            amp_c.run()

            amp_d.input_2 = amp_c.output_signal
            amp_d.run()

            amp_e.input_2 = amp_d.output_signal
            is_complete = amp_e.run()

            if is_complete:
                break

            if amp_e.output_signal > best_score:
                best_score = amp_e.output_signal

    print("Best score: ", best_score)
Esempio n. 2
0
def part_a(instructions):

    phase_settings = get_phase_settings()
    best_score = 0
    for i in range(len(phase_settings)):
        phase_setting = phase_settings[i]

        amp_a, amp_b, amp_c, amp_d, amp_e = Computer(instructions), Computer(
            instructions), Computer(instructions), Computer(
                instructions), Computer(instructions)

        amp_a.input_1 = phase_setting[0]
        amp_b.input_1 = phase_setting[1]
        amp_c.input_1 = phase_setting[2]
        amp_d.input_1 = phase_setting[3]
        amp_e.input_1 = phase_setting[4]

        amp_a.input_2 = 0
        amp_a.run()

        amp_b.input_2 = amp_a.output_signal
        amp_b.run()

        amp_c.input_2 = amp_b.output_signal
        amp_c.run()

        amp_d.input_2 = amp_c.output_signal
        amp_d.run()

        amp_e.input_2 = amp_d.output_signal
        amp_e.run()

        if amp_e.output_signal > best_score:
            best_score = amp_e.output_signal

    print("Best score: ", best_score)