Working out solutions for Advent of Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

02b.py 809B

123456789101112131415161718192021222324252627282930
  1. # Python 3.7
  2. import copy
  3. def main():
  4. instrs = ""
  5. with open("02in.txt","r") as file:
  6. instrs = file.readline()
  7. instrs.strip('\n')
  8. ints = [int(x) for x in instrs.split(',')]
  9. default_ints = copy.deepcopy(ints)
  10. for j in range(100):
  11. for k in range(100):
  12. ints = copy.deepcopy(default_ints)
  13. ints[1] = j
  14. ints[2] = k
  15. i = 0
  16. while ints[i] != 99:
  17. if ints[i] == 1:
  18. v = ints[ints[i+1]] + ints[ints[i+2]]
  19. if ints[i] == 2:
  20. v = ints[ints[i+1]] * ints[ints[i+2]]
  21. ints[ints[i+3]] = v
  22. i += 4
  23. if ints[0] == 19690720:
  24. print((100*j) + k)
  25. return
  26. if __name__ == "__main__":
  27. main()