Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. lst, param, ptr, skip = [int(i) for i in open('day_5_input.txt').read().split(',')], {}, 0, (4,4,2,2,3,3,4,4)
  2. while lst[ptr] != 99:
  3.     opcode = lst[ptr] % 100
  4.     for i in range(1,4): param[str(i)] = ptr + i if lst[ptr]//int('100'.ljust(i+2, '0')) % 10 else lst[ptr + i]
  5.     if opcode is 1: lst[param['3']] = lst[param['1']] + lst[param['2']]
  6.     elif opcode is 2: lst[param['3']] = lst[param['1']] * lst[param['2']]
  7.     elif opcode is 3: lst[param['1']] = int(input('1 or 5?: '))
  8.     elif opcode is 4: print(lst[param['1']])
  9.     elif opcode is 5 and lst[param['1']] or opcode is 6 and not lst[param['1']]: ptr = lst[param['2']] - 3
  10.     elif opcode is 7: lst[param['3']] = 1 if lst[param['1']] < lst[param['2']] else 0
  11.     elif opcode is 8: lst[param['3']] = 1 if lst[param['1']] == lst[param['2']] else 0
  12.     ptr += skip[opcode-1]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement