Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- with open("puzzle_input_2.txt") as f:
- lineList = f.read().split(',')
- #print (lineList)
- #print (len(lineList))
- def addition(lineList, x):
- next_item = int(lineList[x + 1])
- second_next = int(lineList[x + 2])
- position = int(lineList[x + 3])
- lineList[position] = int(lineList[next_item]) + int(lineList[second_next])
- def multiplication(lineList,x):
- next_item = int(lineList[x + 1])
- second_next = int(lineList[x + 2])
- position = int(lineList[x + 3])
- lineList[position] = int(lineList[next_item]) * int(lineList[second_next])
- def intcode_program(lineList):
- for i in range (0,len(lineList),4):
- if int(lineList[i]) == 1:
- addition(lineList, i)
- else:
- if int(lineList[i]) == 2:
- multiplication(lineList,i)
- else:
- break
- intcode_program(lineList)
- lineList[0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement