Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.36 KB | None | 0 0
  1. import copy
  2. from builtins import input
  3.  
  4. step = 4
  5. add = 1
  6. multiply = 2
  7. stop = 99
  8. store = 3
  9. output = 4
  10. mode = None
  11. index = 0
  12.  
  13. intput = 5
  14.  
  15. for line in open("input.txt"):
  16.     input_list = line.split(",")
  17.     input_list = [int(x) for x in input_list]
  18.     #input_list = [1101,100,-1,4,0]
  19.     #input_list[1] = 12
  20.     #input_list[2] = 2
  21.    
  22.     while input_list[index] != stop:
  23.  
  24.         digits = []
  25.         for digit in str(input_list[index]):
  26.             digits.append(digit)
  27.  
  28.         length_of_instruction = len(digits)
  29.  
  30.         while len(digits) < 5 :
  31.             digits.insert(0,"0")
  32.  
  33.         optcode = str(digits[-2])+str(digits[-1])
  34.         mode_first_parameter = digits[-3]
  35.         mode_second_paramater = digits[-4]
  36.         mode_third_parameter = digits[-5]
  37.  
  38.  
  39.         if optcode == "01":
  40.             value_first_parameter = None
  41.             if mode_first_parameter == "1":
  42.                 value_first_parameter = input_list[index + 1]
  43.             elif mode_first_parameter == "0":
  44.                 value_first_parameter = input_list[input_list[index + 1]]
  45.  
  46.             value_second_parameter = None
  47.             if mode_second_paramater == "1":
  48.                 value_second_parameter = input_list[index + 2]
  49.             elif mode_second_paramater == "0":
  50.                 value_second_parameter = input_list[input_list[index + 2]]
  51.  
  52.             input_list[input_list[index+3]] = value_first_parameter+value_second_parameter
  53.             index += 4
  54.         elif optcode == "02":
  55.             value_first_parameter = None
  56.             if mode_first_parameter == "1":
  57.                 value_first_parameter = input_list[index + 1]
  58.             elif mode_first_parameter == "0":
  59.                 value_first_parameter = input_list[input_list[index + 1]]
  60.  
  61.             value_second_parameter = None
  62.             if mode_second_paramater == "1":
  63.                 value_second_parameter = input_list[index + 2]
  64.             elif mode_second_paramater == "0":
  65.                 value_second_parameter = input_list[input_list[index + 2]]
  66.  
  67.             input_list[input_list[index + 3]] = value_first_parameter * value_second_parameter
  68.             index += 4
  69.         elif optcode == "03":
  70.             input_list[input_list[index + 1]] = intput
  71.             index += 2
  72.         elif optcode == "04":
  73.             print(input_list[input_list[index+1]])
  74.             index += 2
  75.         elif optcode == "05":
  76.  
  77.             value_first_parameter = None
  78.             if mode_first_parameter == "1":
  79.                 value_first_parameter = input_list[index + 1]
  80.             elif mode_first_parameter == "0":
  81.                 value_first_parameter = input_list[input_list[index + 1]]
  82.  
  83.             value_second_parameter = None
  84.             if mode_second_paramater == "1":
  85.                 value_second_parameter = input_list[index + 2]
  86.             elif mode_second_paramater == "0":
  87.                 value_second_parameter = input_list[input_list[index + 2]]
  88.  
  89.             if value_first_parameter != 0:
  90.                 index = value_second_parameter
  91.             else:
  92.                 index+=3
  93.         elif optcode == "06":
  94.             value_first_parameter = None
  95.             if mode_first_parameter == "1":
  96.                 value_first_parameter = input_list[index + 1]
  97.             elif mode_first_parameter == "0":
  98.                 value_first_parameter = input_list[input_list[index + 1]]
  99.  
  100.             value_second_parameter = None
  101.             if mode_second_paramater == "1":
  102.                 value_second_parameter = input_list[index + 2]
  103.             elif mode_second_paramater == "0":
  104.                 value_second_parameter = input_list[input_list[index + 2]]
  105.  
  106.             if value_first_parameter == 0:
  107.                 index = value_second_parameter
  108.             else:
  109.                 index+=3
  110.         elif optcode == "07":
  111.  
  112.             value_first_parameter = None
  113.             if mode_first_parameter == "1":
  114.                 value_first_parameter = input_list[index + 1]
  115.             elif mode_first_parameter == "0":
  116.                 value_first_parameter = input_list[input_list[index + 1]]
  117.  
  118.             value_second_parameter = None
  119.             if mode_second_paramater == "1":
  120.                 value_second_parameter = input_list[index + 2]
  121.             elif mode_second_paramater == "0":
  122.                 value_second_parameter = input_list[input_list[index + 2]]
  123.  
  124.             if value_first_parameter < value_second_parameter:
  125.                 input_list[input_list[index + 3]] = 1
  126.             else:
  127.                 input_list[input_list[index + 3]] = 0
  128.             index+=4
  129.         elif optcode == "08":
  130.             value_first_parameter = None
  131.             if mode_first_parameter == "1":
  132.                 value_first_parameter = input_list[index + 1]
  133.             elif mode_first_parameter == "0":
  134.                 value_first_parameter = input_list[input_list[index + 1]]
  135.  
  136.             value_second_parameter = None
  137.             if mode_second_paramater == "1":
  138.                 value_second_parameter = input_list[index + 2]
  139.             elif mode_second_paramater == "0":
  140.                 value_second_parameter = input_list[input_list[index + 2]]
  141.  
  142.             if value_first_parameter == value_second_parameter:
  143.                 input_list[input_list[index + 3]] = 1
  144.             else:
  145.                 input_list[input_list[index + 3]] = 0
  146.             index+=4
  147.  
  148.     print(input_list)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement