Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import copy
- from builtins import input
- step = 4
- add = 1
- multiply = 2
- stop = 99
- store = 3
- output = 4
- mode = None
- index = 0
- intput = 5
- for line in open("input.txt"):
- input_list = line.split(",")
- input_list = [int(x) for x in input_list]
- #input_list = [1101,100,-1,4,0]
- #input_list[1] = 12
- #input_list[2] = 2
- while input_list[index] != stop:
- digits = []
- for digit in str(input_list[index]):
- digits.append(digit)
- length_of_instruction = len(digits)
- while len(digits) < 5 :
- digits.insert(0,"0")
- optcode = str(digits[-2])+str(digits[-1])
- mode_first_parameter = digits[-3]
- mode_second_paramater = digits[-4]
- mode_third_parameter = digits[-5]
- if optcode == "01":
- value_first_parameter = None
- if mode_first_parameter == "1":
- value_first_parameter = input_list[index + 1]
- elif mode_first_parameter == "0":
- value_first_parameter = input_list[input_list[index + 1]]
- value_second_parameter = None
- if mode_second_paramater == "1":
- value_second_parameter = input_list[index + 2]
- elif mode_second_paramater == "0":
- value_second_parameter = input_list[input_list[index + 2]]
- input_list[input_list[index+3]] = value_first_parameter+value_second_parameter
- index += 4
- elif optcode == "02":
- value_first_parameter = None
- if mode_first_parameter == "1":
- value_first_parameter = input_list[index + 1]
- elif mode_first_parameter == "0":
- value_first_parameter = input_list[input_list[index + 1]]
- value_second_parameter = None
- if mode_second_paramater == "1":
- value_second_parameter = input_list[index + 2]
- elif mode_second_paramater == "0":
- value_second_parameter = input_list[input_list[index + 2]]
- input_list[input_list[index + 3]] = value_first_parameter * value_second_parameter
- index += 4
- elif optcode == "03":
- input_list[input_list[index + 1]] = intput
- index += 2
- elif optcode == "04":
- print(input_list[input_list[index+1]])
- index += 2
- elif optcode == "05":
- value_first_parameter = None
- if mode_first_parameter == "1":
- value_first_parameter = input_list[index + 1]
- elif mode_first_parameter == "0":
- value_first_parameter = input_list[input_list[index + 1]]
- value_second_parameter = None
- if mode_second_paramater == "1":
- value_second_parameter = input_list[index + 2]
- elif mode_second_paramater == "0":
- value_second_parameter = input_list[input_list[index + 2]]
- if value_first_parameter != 0:
- index = value_second_parameter
- else:
- index+=3
- elif optcode == "06":
- value_first_parameter = None
- if mode_first_parameter == "1":
- value_first_parameter = input_list[index + 1]
- elif mode_first_parameter == "0":
- value_first_parameter = input_list[input_list[index + 1]]
- value_second_parameter = None
- if mode_second_paramater == "1":
- value_second_parameter = input_list[index + 2]
- elif mode_second_paramater == "0":
- value_second_parameter = input_list[input_list[index + 2]]
- if value_first_parameter == 0:
- index = value_second_parameter
- else:
- index+=3
- elif optcode == "07":
- value_first_parameter = None
- if mode_first_parameter == "1":
- value_first_parameter = input_list[index + 1]
- elif mode_first_parameter == "0":
- value_first_parameter = input_list[input_list[index + 1]]
- value_second_parameter = None
- if mode_second_paramater == "1":
- value_second_parameter = input_list[index + 2]
- elif mode_second_paramater == "0":
- value_second_parameter = input_list[input_list[index + 2]]
- if value_first_parameter < value_second_parameter:
- input_list[input_list[index + 3]] = 1
- else:
- input_list[input_list[index + 3]] = 0
- index+=4
- elif optcode == "08":
- value_first_parameter = None
- if mode_first_parameter == "1":
- value_first_parameter = input_list[index + 1]
- elif mode_first_parameter == "0":
- value_first_parameter = input_list[input_list[index + 1]]
- value_second_parameter = None
- if mode_second_paramater == "1":
- value_second_parameter = input_list[index + 2]
- elif mode_second_paramater == "0":
- value_second_parameter = input_list[input_list[index + 2]]
- if value_first_parameter == value_second_parameter:
- input_list[input_list[index + 3]] = 1
- else:
- input_list[input_list[index + 3]] = 0
- index+=4
- print(input_list)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement