Solutions to Advent of Code 2017 https://adventofcode.com/2017/
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.

12.py 514B

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