Advertisement
icarussiano

day 4 python

Dec 3rd, 2023 (edited)
775
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.41 KB | None | 0 0
  1. f = open("input").read().splitlines()
  2. d = dict(zip(range(1, len(f) + 1), [1] * len(f)))
  3. s = 0
  4. for line in f:
  5.     id = int(line.split(":")[0].split()[1])
  6.     n1, n2 = [set(map(int, x.split())) for x in line.split(":")[1].split("|")]
  7.     s += 2**(len(n1 & n2)-1) if n1 & n2 else 0
  8.     d.update({i: d[i]+d[id] for i in range(id + 1, id + 1 + len(n1 & n2))})
  9.  
  10. print(f"Part 1: {s}",f"Part 2: {sum(d.values())}")
  11.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement