Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- filename = 'puzzleinput.txt'
- with open(filename, 'r') as f:
- intcode = f.read().rstrip()
- original_intcode = [int(num) for num in intcode.split(',')]
- intcode = original_intcode[:]
- def intcode_translator(intcode):
- """Translate intcode.
- Intcode is a list of numbers, each 4 numbers x.y.z.d represents;
- x = operation, 1 for +, 2 for *.
- y = the position of the first input.
- z = the position of the second input.
- d = the position to save the result of the operation.
- """
- opcode = intcode[0::4]
- first_num = intcode[1::4]
- second_num = intcode[2::4]
- save_position = intcode[3::4]
- index = 0
- while True:
- for num in opcode:
- if num == 1:
- intcode[save_position[index]] = ( intcode[first_num[index]]
- + intcode[second_num[index]] )
- index += 1
- elif num == 2:
- intcode[save_position[index]] = ( intcode[first_num[index]]
- * intcode[second_num[index]] )
- index += 1
- elif num == 99:
- break
- break
- count = 0
- while True:
- for i in range(99):
- intcode[1] = i
- intcode_translator(intcode)
- if intcode[0] == 19690720:
- break
- else:
- intcode = original_intcode[:]
- intcode[2] = count
- if intcode[0] == 19690720:
- break
- else:
- count += 1
- intcode[2] = count
- print('\nThe translated incode list:')
- print(intcode)
- print('\nThe original list:')
- print(original_intcode)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement