Working out solutions for Advent of Code
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

1234567891011121314151617181920212223242526
  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 "Found after {} cycles: {}".format(cycles,freq)
  20. freqlist.append(freq)
  21. if __name__ == "__main__":
  22. args = input("Paste the modulations here: ")
  23. print(main(args))