Solutions to Advent of Code 2017 https://adventofcode.com/2017/
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910
  1. from shared import add_connected_components
  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. add_connected_components(sets, pipe)
  7. print(f'Part one: {len(next(s for s in sets if "0" in s))}')
  8. print(f'Part two: {len(sets)}')