My solutions to 2018's 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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

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'))))