Working out solutions for Advent of Code
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

il y a 5 ans
il y a 5 ans
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))