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.

02.py 637B

123456789101112131415161718192021222324252627
  1. import itertools
  2. import operator
  3. def count_dupes(box):
  4. return [any(box.count(x) == i for x in box) for i in (2, 3)]
  5. with open('data/02.txt', 'r') as file:
  6. boxes = list(map(str.strip, file.readlines()))
  7. print(operator.mul(*map(sum, zip(*map(count_dupes, boxes)))))
  8. for box1, box2 in itertools.combinations(boxes, 2):
  9. common = ''
  10. missed = 0
  11. for i, j in zip(box1, box2):
  12. if i == j:
  13. common += i
  14. else:
  15. missed += 1
  16. if missed > 1:
  17. break
  18. if missed == 1:
  19. print(common)
  20. break