-
Notifications
You must be signed in to change notification settings - Fork 0
/
7.py
33 lines (23 loc) · 931 Bytes
/
7.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import intcomp as ic
from itertools import permutations
def runPhaseSequence(intcode, phase_sequence):
input_signal = 0
for phase_setting in phase_sequence:
inputs = [phase_setting, input_signal]
output = ic.process(intcode, input_queue=inputs)
input_signal = output[1][0]
return output[1][0]
if __name__ == "__main__":
with open("input/7.input", "r") as file:
intcode = ic.parseFromString(file.read())
phases = [0,1,2,3,4]
phase_sequences = permutations(phases)
outputs = []
for phase_sequence in phase_sequences:
output = runPhaseSequence(intcode, phase_sequence)
outputs.append(output)
print("Part 1 | highest thruster signal:", max(outputs))
print("Part 2 | the writer of this problem really needs an editor for clarity")
print("Part 2 | but as far as i understand it, with pausing execution,")
print("Part 2 | waiting for inputs and all that jazz:")
print("Part 2 | sod this, actually")