Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- f = open("input").read().splitlines()
- d = dict(zip(range(1, len(f) + 1), [1] * len(f)))
- s = 0
- for line in f:
- id = int(line.split(":")[0].split()[1])
- n1, n2 = [set(map(int, x.split())) for x in line.split(":")[1].split("|")]
- s += 2**(len(n1 & n2)-1) if n1 & n2 else 0
- d.update({i: d[i]+d[id] for i in range(id + 1, id + 1 + len(n1 & n2))})
- print(f"Part 1: {s}",f"Part 2: {sum(d.values())}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement