예제 #1
0
파일: 07.py 프로젝트: lorimer1/aoc-2019
            for phase_d in range(5):
                if phase_d in [phase_a, phase_b, phase_c]:
                    continue

                for phase_e in range(5):
                    if phase_e in [phase_a, phase_b, phase_c, phase_d]:
                        continue

                    amp_a.reset()
                    amp_b.reset()
                    amp_c.reset()
                    amp_d.reset()
                    amp_e.reset()

                    amp_a.run([phase_a, 0])
                    amp_b.run([phase_b, amp_a.output()])
                    amp_c.run([phase_c, amp_b.output()])
                    amp_d.run([phase_d, amp_c.output()])
                    amp_e.run([phase_e, amp_d.output()])

                    if amp_e.output() > max_output:
                        max_output = amp_e.output()

print("Part 1:", max_output)

max_output = 0

for phase_a in range(5, 10):

    for phase_b in range(5, 10):
예제 #2
0
file = open('input.txt')
initial_data = list(map(int, file.read().split(',')))

#initial_data = [3,15,3,16,1002,16,10,16,1,16,15,15,4,15,99,0,0]
#initial_data = [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]

phase_permutations = permutations(range(5), 5)

print('Starting Part 1 diagnostics')
max_thrust = 0
for phases in phase_permutations:
    ampA = Amplifier(initial_data)
    ampA.set_phase(phases[0])
    ampA.set_input(0)
    ampA.run()
    ampB = Amplifier(initial_data)
    ampB.set_phase(phases[1])
    ampB.set_input(ampA.get_output())
    ampB.run()
    ampC = Amplifier(initial_data)
    ampC.set_phase(phases[2])
    ampC.set_input(ampB.get_output())
    ampC.run()
    ampD = Amplifier(initial_data)
    ampD.set_phase(phases[3])
    ampD.set_input(ampC.get_output())
    ampD.run()
    ampE = Amplifier(initial_data)
    ampE.set_phase(phases[4])
    ampE.set_input(ampD.get_output())