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.

1234567891011121314151617181920212223242526272829303132333435
  1. """ Advent of Code Day 5a
  2. """
  3. def comp(s1,s2):
  4. if (s1 != s2) and s1.lower() == s2.lower():
  5. return True
  6. return False
  7. def main(polymer):
  8. opoly = polymer
  9. do_it = True
  10. while do_it:
  11. olen = len(polymer)
  12. print(olen)
  13. for i in range(len(polymer)-1):
  14. if comp(polymer[i], polymer[i+1]):
  15. if i == 0: # the first two are a match
  16. polymer = polymer[2:]
  17. elif i == (olen - 2): # the last two are a match
  18. polymer = polymer[:-2]
  19. else: # the match is in the middle
  20. polymer = polymer[:i] + polymer[i+2:]
  21. break
  22. if olen == len(polymer): # we didn't reduce polymer's length at all
  23. do_it = False # no more matches, stop looping
  24. print(len(polymer))
  25. if __name__ == "__main__":
  26. inline = ""
  27. with open("05in.txt","r") as ofile:
  28. inline = ofile.read().strip()
  29. main(inline)