Advertisement
Musical_Muze

Day 7, Part 2

Dec 12th, 2019
787
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. from intcode_class import Intcode
  2. from itertools import permutations
  3.  
  4. #get a two-dimentional array of all permutations of the numbers 5 through 9
  5. perms = list(permutations(range(5,10)))
  6. for i in range(len(perms)):
  7.     perms[i] = list(perms[i])
  8.  
  9. highOutput = 0
  10. highArray = []
  11. file1 = "input.txt"
  12.  
  13. for x in perms:
  14.    
  15.     amp1 = Intcode("Amplifier 1", file1, x[0], 0)
  16.     amp2 = Intcode("Amplifier 2", file1, x[1], 0)
  17.     amp3 = Intcode("Amplifier 3", file1, x[2], 0)
  18.     amp4 = Intcode("Amplifier 4", file1, x[3], 0)
  19.     amp5 = Intcode("Amplifier 5", file1, x[4], 0)
  20.  
  21.     output = 0
  22.  
  23.     while(amp5.getCode() != 99):
  24.         output = amp5.ampRun(amp4.ampRun(amp3.ampRun(amp2.ampRun(amp1.ampRun(output)))))
  25.         if(output != None):
  26.             if(output>highOutput):
  27.                 highOutput = output
  28.                 highArray = x
  29.  
  30. print("The highest output permutation was " + str(highArray))
  31. print("with an output of " + str(highOutput))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement