Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. set i 31
  2. set a 1
  3. mul p 17
  4. jgz p p
  5. mul a 2
  6. add i -1
  7. jgz i -2
  8. add a -1
  9. set i 127
  10. set p 680
  11. mul p 8505
  12. mod p a
  13. mul p 129749
  14. add p 12345
  15. mod p a
  16. set b p
  17. mod b 10000
  18. snd b
  19. add i -1
  20. jgz i -9
  21. jgz a 3
  22. rcv b
  23. jgz b -1
  24. set f 0
  25. set i 126
  26. rcv a
  27. rcv b
  28. set p a
  29. mul p -1
  30. add p b
  31. jgz p 4
  32. snd a
  33. set a b
  34. jgz 1 3
  35. snd b
  36. set f 1
  37. add i -1
  38. jgz i -11
  39. snd a
  40. jgz f -16
  41. jgz a -19
  42.  
  43. instructions = []
  44. registers = {}
  45.  
  46. file=open("day18.txt")
  47. for line in file:
  48. data = line.strip("\n\r").split(" ")
  49. instructions.append(data)
  50.  
  51. running = True
  52.  
  53. current = 0
  54.  
  55. while running:
  56. if instructions[current][1] not in registers:
  57. #registers[str(instructions[current][1])] == 0
  58. registers.update({instructions[current][1]: 0})
  59.  
  60. if instructions[current][0] == "snd":
  61. print instructions[current][1]
  62.  
  63. if instructions[current][0] == "set":
  64. try:
  65. registers[instructions[current][1]] = int(instructions[current][2])
  66. except:
  67. registers[instructions[current][1]] = registers[instructions[current][2]]
  68.  
  69. if instructions[current][0] == "add":
  70. try:
  71. registers[instructions[current][1]] += int(instructions[current][2])
  72. except:
  73. registers[instructions[current][1]] += registers[instructions[current][2]]
  74.  
  75. if instructions[current][0] == "mul":
  76. try:
  77. registers[instructions[current][1]] *= int(instructions[current][2])
  78. except:
  79. registers[instructions[current][1]] *= registers[instructions[current][2]]
  80.  
  81. if instructions[current][0] == "mod":
  82. try:
  83. registers[instructions[current][1]] = registers[instructions[current][1]] % int(instructions[current][2])
  84. except:
  85. registers[instructions[current][1]] = registers[instructions[current][1]] % registers[instructions[current][2]]
  86.  
  87. if instructions[current][0] == "rcv":
  88. if instructions[current][1] != "0":
  89. print instructions[current]
  90. exit()
  91. if instructions[current][0] == "jgz":
  92. try:
  93. if int(instructions[current][1]) > 0:
  94. current += int(instructions[current][1])
  95. except:
  96. if registers[instructions[current][1]] > 0:
  97. current += registers[instructions[current][1]]
  98.  
  99. else:
  100. current += 1
  101. if current <0 or current >= len(instructions):
  102. print "outside list"
  103. exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement