05.py
1 from lib import * 2 3 input = read_input(2021, 5) 4 5 6 seen = set() 7 dup = set() 8 for line in input.splitlines(): 9 a, b = line.split(" -> ") 10 x1, y1 = map(int, a.split(",")) 11 x2, y2 = map(int, b.split(",")) 12 if x1 != x2 and y1 != y2: 13 continue 14 15 for x, y in iter_line(x1, y1, x2, y2): 16 if (x, y) in seen: 17 dup.add((x, y)) 18 19 seen.add((x, y)) 20 21 print(len(dup)) 22 23 24 seen = set() 25 dup = set() 26 for line in input.splitlines(): 27 a, b = line.split(" -> ") 28 x1, y1 = map(int, a.split(",")) 29 x2, y2 = map(int, b.split(",")) 30 for x, y in iter_line(x1, y1, x2, y2): 31 if (x, y) in seen: 32 dup.add((x, y)) 33 34 seen.add((x, y)) 35 36 print(len(dup))