Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # computer = [3,0,4,0,3,0,4,0,99]
- # computer = [1101,100,-1,4,0]
- computer = [data here]
- current_index = 0
- while(current_index < len(computer)):
- if(computer[current_index] == 1):
- computer[computer[current_index + 3]] = computer[computer[current_index + 1]] + computer[computer[current_index + 2]]
- current_index += 4
- elif(computer[current_index] == 2):
- computer[computer[current_index + 3]] = computer[computer[current_index + 1]] * computer[computer[current_index + 2]]
- current_index += 4
- elif (computer[current_index] == 3):
- computer[computer[current_index + 1]] = int(input("input: "))
- current_index += 2
- elif (computer[current_index] == 4):
- print("output: ", computer[computer[current_index + 1]])
- current_index += 2
- elif (computer[current_index] == 99):
- break
- else:
- # be careful of comparing chars with ints
- opcode = str(computer[current_index])
- # third parameter always in position mode
- parameter_1_value = computer[current_index + 1] if opcode[1] == '1' else computer[computer[current_index + 1]]
- parameter_2_value = computer[current_index + 2] if opcode[0] == '1' else computer[computer[current_index + 2]]
- output_index = computer[current_index + 3]
- op = int(opcode[len(opcode) - 1])
- if(op == 1):
- computer[output_index] = parameter_1_value + parameter_2_value
- current_index += 4
- elif(op == 2):
- computer[output_index] = parameter_1_value * parameter_2_value
- current_index += 4
- # print(computer[current_index]) # 104 not a command thats why its getting stuck but how?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement