My solutions to 2018's advent of code
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
此仓库已存档。您可以查看文件和克隆,但不能推送或创建工单/合并请求。

12345678910111213141516171819
  1. import re
  2. from collections import defaultdict
  3. with open('data/03.txt', 'r') as file:
  4. cells = defaultdict(list)
  5. claims = map(lambda l: map(int, re.findall(r'\d+', l)), file.readlines())
  6. ids = set()
  7. for (cid, x, y, width, height) in claims:
  8. ids.add(cid)
  9. for i in range(width):
  10. for j in range(height):
  11. cells[(x + i, y + j)].append(cid)
  12. overlaps = [c for c in cells.values() if len(c) > 1]
  13. print(len(overlaps))
  14. dupes = set(cid for sublist in overlaps for cid in sublist)
  15. print(list(ids - dupes)[0])