Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program = []
- with open("8 - input", 'r') as file:
- lines = file.readlines()
- for line in lines:
- line = line.strip("\n")
- program.append([line.split(" ")[0], line.split(" ")[1][0], int(line.split(" ")[1][1:])])
- .
- .
- .
- .
- # part 2
- programBak = program
- triedInstructions = []
- for i in range(0, len(program)):
- program = programBak
- if program[i] not in triedInstructions:
- if program[i][0] == "nop":
- program[i][0] = "jmp"
- print(f"Switched instruction {programBak[i]} at {i} to {program[i]}")
- triedInstructions.append(program[i])
- elif program[i][0] == "jmp":
- program[i][0] = "nop"
- print(f"Switched instruction {programBak[i]} at {i} to {program[i]}")
- triedInstructions.append(program[i])
- result = runProgram(program)
- print(result)
- if result[2] == "Out of bounds":
- exit(0)
- print("Never got errorcode 'Out of bounds'")
- exit(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement