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.

01b.py 724B

12345678910111213141516171819202122232425262728
  1. # Advent of Code 2018
  2. # December 01, puzzle 1
  3. import sys
  4. def main(args):
  5. freqlist = [0]
  6. found = False
  7. cycles = 0
  8. arglist = args.split(",")
  9. arglist = [x.strip() for x in arglist]
  10. freq = 0
  11. while not found:
  12. cycles += 1
  13. for item in arglist:
  14. if item[0] == "+":
  15. freq += int(item[1:])
  16. elif item[0] == "-":
  17. freq -= int(item[1:])
  18. if freq in freqlist:
  19. return freq
  20. freqlist.append(freq)
  21. if cycles == 1000000:
  22. return "I haven't found a duplicate after a million cycles."
  23. if __name__ == "__main__":
  24. args = input("Paste the modulations here: ")
  25. print(main(args))