Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Getting puzzle input
- print('Insert your puzzle input:')
- inp = input()
- #Generating lists
- data = list(map(int, inp.split(',')))
- def parameters(op, command, counter):
- intr = list(str(command))
- parm = ([0]*(5 - len(str(command)))) + intr
- val1 = (op[counter + 1] if int(parm[2]) == 0 else (counter + 1))
- val2 = (op[counter + 2] if int(parm[1]) == 0 else (counter + 2))
- val3 = (op[counter + 3] if int(parm[0]) == 0 else (counter + 3))
- return val1, val2, val3
- #Main calc
- def run1(d):
- counter = 0
- input = 1
- while counter < len(d):
- intr = d[counter]
- opcode = int(str(intr)[-1])
- val1, val2, val3 = parameters(d, intr, counter)
- if opcode == 1:
- d[val3] = d[val1] + d[val2]
- counter += 4
- elif opcode == 2:
- d[val3] = d[val1] * d[val2]
- counter += 4
- elif opcode == 3:
- d[val1] = input
- counter += 2
- elif opcode == 99 or opcode == 4:
- if d[val1] != 0 and d[counter + 2] == 99:
- return d[val1]
- elif d[val1] != 0 and d[counter + 2] != 99:
- return f'Test failed with output {d[val1]}'
- #Running part 1
- def gen1(d):
- result = run1(d)
- return result
- #Running parts
- p1 = gen1(data)
- #Printing results
- print(f'Part 1 Result is {p1}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement