Advertisement
Armandur

Untitled

Dec 8th, 2020
613
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. program = []
  2.  
  3. with open("8 - input", 'r') as file:
  4.     lines = file.readlines()
  5.     for line in lines:
  6.         line = line.strip("\n")
  7.         program.append([line.split(" ")[0], line.split(" ")[1][0], int(line.split(" ")[1][1:])])
  8.  
  9. .
  10. .
  11. .
  12. .
  13.  
  14. # part 2
  15. programBak = program
  16. triedInstructions = []
  17. for i in range(0, len(program)):
  18.     program = programBak
  19.     if program[i] not in triedInstructions:
  20.         if program[i][0] == "nop":
  21.             program[i][0] = "jmp"
  22.             print(f"Switched instruction {programBak[i]} at {i} to {program[i]}")
  23.             triedInstructions.append(program[i])
  24.         elif program[i][0] == "jmp":
  25.             program[i][0] = "nop"
  26.             print(f"Switched instruction {programBak[i]} at {i} to {program[i]}")
  27.             triedInstructions.append(program[i])
  28.         result = runProgram(program)
  29.         print(result)
  30.         if result[2] == "Out of bounds":
  31.             exit(0)
  32.  
  33. print("Never got errorcode 'Out of bounds'")
  34. exit(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement