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.

02a.py 606B

1234567891011121314151617181920212223242526
  1. # Python 3.7
  2. def main(debug):
  3. instrs = ""
  4. if debug:
  5. instrs = "1,1,1,4,99,5,6,0,99"
  6. else:
  7. with open("02in.txt","r") as file:
  8. instrs = file.readline()
  9. instrs.strip('\n')
  10. ints = [int(x) for x in instrs.split(',')]
  11. if not debug:
  12. ints[1] = 12
  13. ints[2] = 2
  14. i = 0
  15. while ints[i] != 99:
  16. if ints[i] == 1:
  17. v = ints[ints[i+1]] + ints[ints[i+2]]
  18. if ints[i] == 2:
  19. v = ints[ints[i+1]] * ints[ints[i+2]]
  20. ints[ints[i+3]] = v
  21. i += 4
  22. print(ints)
  23. if __name__ == "__main__":
  24. main(False)