Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.51 KB | None | 0 0
  1. # computer = [3,0,4,0,3,0,4,0,99]
  2. # computer = [1101,100,-1,4,0]
  3. computer = [3,225,1,225,6,6,1100,1,238,225,104,0,1101,86,8,225,1101,82,69,225,101,36,65,224,1001,224,-106,224,4,224,1002,223,8,223,1001,224,5,224,1,223,224,223,102,52,148,224,101,-1144,224,224,4,224,1002,223,8,223,101,1,224,224,1,224,223,223,1102,70,45,225,1002,143,48,224,1001,224,-1344,224,4,224,102,8,223,223,101,7,224,224,1,223,224,223,1101,69,75,225,1001,18,85,224,1001,224,-154,224,4,224,102,8,223,223,101,2,224,224,1,224,223,223,1101,15,59,225,1102,67,42,224,101,-2814,224,224,4,224,1002,223,8,223,101,3,224,224,1,223,224,223,1101,28,63,225,1101,45,22,225,1101,90,16,225,2,152,92,224,1001,224,-1200,224,4,224,102,8,223,223,101,7,224,224,1,223,224,223,1101,45,28,224,1001,224,-73,224,4,224,1002,223,8,223,101,7,224,224,1,224,223,223,1,14,118,224,101,-67,224,224,4,224,1002,223,8,223,1001,224,2,224,1,223,224,223,4,223,99,0,0,0,677,0,0,0,0,0,0,0,0,0,0,0,1105,0,99999,1105,227,247,1105,1,99999,1005,227,99999,1005,0,256,1105,1,99999,1106,227,99999,1106,0,265,1105,1,99999,1006,0,99999,1006,227,274,1105,1,99999,1105,1,280,1105,1,99999,1,225,225,225,1101,294,0,0,105,1,0,1105,1,99999,1106,0,300,1105,1,99999,1,225,225,225,1101,314,0,0,106,0,0,1105,1,99999,7,677,677,224,102,2,223,223,1005,224,329,1001,223,1,223,1008,226,226,224,1002,223,2,223,1005,224,344,1001,223,1,223,1107,677,226,224,1002,223,2,223,1006,224,359,1001,223,1,223,107,677,677,224,102,2,223,223,1005,224,374,101,1,223,223,1108,677,226,224,102,2,223,223,1005,224,389,1001,223,1,223,1007,677,677,224,1002,223,2,223,1005,224,404,101,1,223,223,1008,677,226,224,102,2,223,223,1005,224,419,101,1,223,223,1108,226,677,224,102,2,223,223,1006,224,434,1001,223,1,223,8,677,226,224,1002,223,2,223,1005,224,449,101,1,223,223,1008,677,677,224,1002,223,2,223,1006,224,464,1001,223,1,223,1108,226,226,224,1002,223,2,223,1005,224,479,1001,223,1,223,1007,226,677,224,102,2,223,223,1005,224,494,1001,223,1,223,1007,226,226,224,102,2,223,223,1005,224,509,101,1,223,223,107,677,226,224,1002,223,2,223,1006,224,524,1001,223,1,223,108,677,677,224,102,2,223,223,1006,224,539,101,1,223,223,7,677,226,224,102,2,223,223,1006,224,554,1001,223,1,223,1107,226,677,224,102,2,223,223,1005,224,569,101,1,223,223,108,677,226,224,1002,223,2,223,1006,224,584,101,1,223,223,108,226,226,224,102,2,223,223,1006,224,599,1001,223,1,223,1107,226,226,224,102,2,223,223,1006,224,614,1001,223,1,223,8,226,677,224,102,2,223,223,1006,224,629,1001,223,1,223,107,226,226,224,102,2,223,223,1005,224,644,101,1,223,223,8,226,226,224,102,2,223,223,1006,224,659,101,1,223,223,7,226,677,224,102,2,223,223,1005,224,674,101,1,223,223,4,223,99,226]
  4. # computer = [1,12,2,3,1,1,2,3,1,3,4,3,1,5,0,3,2,13,1,19,1,10,19,23,1,23,9,27,1,5,27,31,2,31,13,35,1,35,5,39,1,39,5,43,2,13,43,47,2,47,10,51,1,51,6,55,2,55,9,59,1,59,5,63,1,63,13,67,2,67,6,71,1,71,5,75,1,75,5,79,1,79,9,83,1,10,83,87,1,87,10,91,1,91,9,95,1,10,95,99,1,10,99,103,2,103,10,107,1,107,9,111,2,6,111,115,1,5,115,119,2,119,13,123,1,6,123,127,2,9,127,131,1,131,5,135,1,135,13,139,1,139,10,143,1,2,143,147,1,147,10,0,99,2,0,14,0]
  5. # computer = [1002,4,3,4,33]
  6.  
  7. # i mean ... it sort of works, it produces 3 as the first output for some reason ...
  8.  
  9. current_index = 0
  10. while(current_index < len(computer) ):
  11.     # print(current_index)
  12.     if(computer[current_index] == 1):
  13.         computer[computer[current_index + 3]] = computer[computer[current_index + 1]] + computer[computer[current_index + 2]]
  14.         current_index += 4
  15.     elif(computer[current_index] == 2):
  16.         computer[computer[current_index + 3]] = computer[computer[current_index + 1]] * computer[computer[current_index + 2]]
  17.         current_index += 4
  18.     elif (computer[current_index] == 3):
  19.             computer[computer[current_index + 1]] = int(input("input: "))
  20.             current_index += 2
  21.     elif (computer[current_index] == 4):
  22.             print("output: ", computer[computer[current_index + 1]])
  23.             current_index += 2
  24.     elif (computer[current_index] == 99):
  25.         break
  26.     else:
  27.         # be careful of comparing chars with ints
  28.         opcode = str(computer[current_index])
  29.         if(len(opcode) < 4): opcode = "0" + opcode
  30.         op = int(opcode[len(opcode) - 1])
  31.         # THREE DIGIT MINIMUM
  32.         if(op != 4 and op != 3):
  33.             # third parameter always in position mode
  34.             parameter_1_value = computer[current_index + 1] if opcode[1] == '1' else computer[computer[current_index + 1]]
  35.             # 4 HAS ONLY 1 PARAMETER
  36.             parameter_2_value = computer[current_index + 2] if opcode[0] == '1' else computer[computer[current_index + 2]] # calls computer[1101] WHY?
  37.         else:
  38.             parameter_1_value = computer[current_index + 1] if opcode[1] == '1' else computer[computer[current_index + 1]]
  39.  
  40.         output_index = computer[current_index + 3]
  41.  
  42.         # 104 is interpreted as 0104 with a leading 0 <<<<<< IMPORTANT
  43.         if(op == 1):
  44.             computer[output_index] = parameter_1_value + parameter_2_value
  45.             # print(parameter_1_value)
  46.             current_index += 4
  47.         elif(op == 2):
  48.             computer[output_index] = parameter_1_value * parameter_2_value
  49.             current_index += 4
  50.         elif(op == 3):
  51.             computer[computer[current_index + 1]] = int(input("input: "))
  52.             current_index += 2
  53.         elif(op == 4):
  54.             # print(computer)
  55.             print("output: ", computer[computer[current_index + 1]])
  56.             current_index += 2
  57.  
  58.     # print(computer) # 104 not a command thats why its getting stuck but how?
  59.     # if(current_index > 9):
  60.     #     break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement