6 def get_possible_change_locations(instructions):
9 for instruction,param in instructions:
10 if instruction == "nop":
11 change_locations.append(instruction_location)
12 elif instruction == "jmp":
13 change_locations.append(instruction_location)
14 instruction_location+=1
15 return change_locations
18 # read the instructions
19 instructions=[line.rstrip().split(" ") for line in open("input.txt", "r")]
20 possible_change_locations=get_possible_change_locations(instructions)
22 for change_location in possible_change_locations:
23 new_instructions=copy.deepcopy(instructions)
24 instruction = new_instructions[change_location][0]
25 param = new_instructions[change_location][1]
26 if instruction == "nop":
31 new_instructions[change_location][0]=instruction
33 comp=computer.Computer(new_instructions,break_on_exec=10)
35 if comp.exited_on_break():
38 print ("Replaced instruction at pos: {}, computer terminated normally with acc: {}".format(change_location, acc))
41 if __name__ == "__main__":