b.py (877B) [raw]
1 #!/usr/bin/env python3 2 import sys 3 import pdb 4 from collections import defaultdict 5 6 grid = defaultdict(lambda: defaultdict(int)) 7 8 def bigrange(a, b): 9 # NOTE: unlike a.py, reversed is impt! 10 if a > b: 11 return reversed(range(b, a + 1)) 12 else: 13 return range(a, b + 1) 14 15 for l in sys.stdin: 16 a, arrow, b = l.split() 17 x1, y1 = [int(x) for x in a.split(',')] 18 x2, y2 = [int(x) for x in b.split(',')] 19 if x1 == x2: 20 for y in bigrange(y1, y2): 21 grid[x1][y] += 1 22 elif y1 == y2: 23 for x in bigrange(x1, x2): 24 grid[x][y1] += 1 25 else: 26 xr = bigrange(x1, x2) 27 yr = bigrange(y1, y2) 28 coords = zip(xr, yr) 29 for x, y in coords: 30 grid[x][y] += 1 31 32 count = 0 33 for x in grid.keys(): 34 for y in grid[x].keys(): 35 if grid[x][y] > 1: 36 count += 1 37 38 print(count)