Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. import math
  2.  
  3. with open("puzzle_input_2.txt") as f:
  4. lineList = f.read().split(',')
  5. #print (lineList)
  6. #print (len(lineList))
  7.  
  8. def addition(lineList, x):
  9. next_item = int(lineList[x + 1])
  10. second_next = int(lineList[x + 2])
  11. position = int(lineList[x + 3])
  12. lineList[position] = int(lineList[next_item]) + int(lineList[second_next])
  13.  
  14.  
  15. def multiplication(lineList,x):
  16. next_item = int(lineList[x + 1])
  17. second_next = int(lineList[x + 2])
  18. position = int(lineList[x + 3])
  19. lineList[position] = int(lineList[next_item]) * int(lineList[second_next])
  20.  
  21. def intcode_program(lineList):
  22. for i in range (0,len(lineList),4):
  23. if int(lineList[i]) == 1:
  24. addition(lineList, i)
  25. else:
  26. if int(lineList[i]) == 2:
  27. multiplication(lineList,i)
  28. else:
  29. break
  30.  
  31. intcode_program(lineList)
  32. lineList[0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement