Solutions to Advent of Code 2017 https://adventofcode.com/2017/
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213
  1. import functools
  2. with open('data/12.txt', 'r') as file:
  3. sets = []
  4. pipes = list(map(lambda l: l.strip().replace(' <-> ', ', ').split(', '), file.readlines()))
  5. for pipe in pipes:
  6. overlapping = [s for s in sets if any(program in s for program in pipe)]
  7. for overlap in overlapping:
  8. sets.remove(overlap)
  9. sets.append(functools.reduce(set.union, overlapping, set(pipe)))
  10. print(f'Part one: {len(next(s for s in sets if "0" in s))}')
  11. print(f'Part two: {len(sets)}')