Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set i 31
- set a 1
- mul p 17
- jgz p p
- mul a 2
- add i -1
- jgz i -2
- add a -1
- set i 127
- set p 680
- mul p 8505
- mod p a
- mul p 129749
- add p 12345
- mod p a
- set b p
- mod b 10000
- snd b
- add i -1
- jgz i -9
- jgz a 3
- rcv b
- jgz b -1
- set f 0
- set i 126
- rcv a
- rcv b
- set p a
- mul p -1
- add p b
- jgz p 4
- snd a
- set a b
- jgz 1 3
- snd b
- set f 1
- add i -1
- jgz i -11
- snd a
- jgz f -16
- jgz a -19
- instructions = []
- registers = {}
- file=open("day18.txt")
- for line in file:
- data = line.strip("\n\r").split(" ")
- instructions.append(data)
- running = True
- current = 0
- while running:
- if instructions[current][1] not in registers:
- #registers[str(instructions[current][1])] == 0
- registers.update({instructions[current][1]: 0})
- if instructions[current][0] == "snd":
- print instructions[current][1]
- if instructions[current][0] == "set":
- try:
- registers[instructions[current][1]] = int(instructions[current][2])
- except:
- registers[instructions[current][1]] = registers[instructions[current][2]]
- if instructions[current][0] == "add":
- try:
- registers[instructions[current][1]] += int(instructions[current][2])
- except:
- registers[instructions[current][1]] += registers[instructions[current][2]]
- if instructions[current][0] == "mul":
- try:
- registers[instructions[current][1]] *= int(instructions[current][2])
- except:
- registers[instructions[current][1]] *= registers[instructions[current][2]]
- if instructions[current][0] == "mod":
- try:
- registers[instructions[current][1]] = registers[instructions[current][1]] % int(instructions[current][2])
- except:
- registers[instructions[current][1]] = registers[instructions[current][1]] % registers[instructions[current][2]]
- if instructions[current][0] == "rcv":
- if instructions[current][1] != "0":
- print instructions[current]
- exit()
- if instructions[current][0] == "jgz":
- try:
- if int(instructions[current][1]) > 0:
- current += int(instructions[current][1])
- except:
- if registers[instructions[current][1]] > 0:
- current += registers[instructions[current][1]]
- else:
- current += 1
- if current <0 or current >= len(instructions):
- print "outside list"
- exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement