Skip to content

Instantly share code, notes, and snippets.

@ntreu14
Created December 2, 2019 15:45
Show Gist options
  • Select an option

  • Save ntreu14/465725567bddc8c8918a56dbb23a5ae1 to your computer and use it in GitHub Desktop.

Select an option

Save ntreu14/465725567bddc8c8918a56dbb23a5ae1 to your computer and use it in GitHub Desktop.
Solution for Advent of Code 2019 Day 2 Part 1
from collections import deque
puzzle_input = deque([1,12,2,3,1,1,2,3,1,3,4,3,1,5,0,3,2,10,1,19,1,19,9,23,1,23,6,27,2,27,13,31,1,10,31,35,1,10,35,39,2,39,6,43,1,43,5,47,2,10,47,51,1,5,51,55,1,55,13,59,1,59,9,63,2,9,63,67,1,6,67,71,1,71,13,75,1,75,10,79,1,5,79,83,1,10,83,87,1,5,87,91,1,91,9,95,2,13,95,99,1,5,99,103,2,103,9,107,1,5,107,111,2,111,9,115,1,115,6,119,2,13,119,123,1,123,5,127,1,127,9,131,1,131,10,135,1,13,135,139,2,9,139,143,1,5,143,147,1,13,147,151,1,151,2,155,1,10,155,0,99,2,14,0,0])
def storeInRegister(amount, register, problem_input):
problem_input[register] = amount
def solve(problem_input):
rotation_amount = 0
while problem_input[0] <> 99:
op_code = problem_input[0]
register1 = problem_input[1]
register2 = problem_input[2]
toRegister = problem_input[3]
# Back to original State
problem_input.rotate(abs(rotation_amount))
if op_code == 1:
storeInRegister(problem_input[register1] + problem_input[register2], toRegister, problem_input)
if op_code == 2:
storeInRegister(problem_input[register1] * problem_input[register2], toRegister, problem_input)
rotation_amount -= 4
problem_input.rotate(rotation_amount)
problem_input.rotate(abs(rotation_amount))
return problem_input[0]
if __name__ == '__main__':
print solve(puzzle_input)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment