My solutions to 2018's advent of code
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
Tento repozitář je archivovaný. Můžete prohlížet soubory, klonovat, ale nemůžete nahrávat a vytvářet nové úkoly a požadavky na natažení.

05.py 530B

1234567891011121314151617181920
  1. from functools import partial, reduce
  2. with open('data/05.txt', 'r') as file:
  3. polymer = map(ord, file.readline().strip())
  4. def react(ignored, head, n):
  5. if n == ignored or n ^ ignored == 32:
  6. return head
  7. elif not head:
  8. return [n]
  9. elif head[-1] ^ n == 32:
  10. return head[0:-1]
  11. else:
  12. return head + [n]
  13. reacted = reduce(partial(react, 0), polymer, [])
  14. print(len(reacted))
  15. print(min(len(reduce(partial(react, i), reacted, [])) for i in range(ord('A'), ord('Z'))))