8 lines
803 B
Python
8 lines
803 B
Python
import sys
|
|
from collections import Counter
|
|
with open('./2021/05.input', 'r') as f:
|
|
# with open('./2021/05.test', 'r') as f:
|
|
f = [[list(map(int, y.split(','))) for y in x.split("->")] for x in f.read().splitlines()]
|
|
|
|
print(sum([1 for k, v in Counter([item for sublist in [[(x, y) for x in range(min(x0, x1), max(x0, x1) + 1) for y in range(min(y0, y1), max(y0, y1) + 1) if ((x - x0) * (y1 - y0) - (y - y0) * (x1 - x0)) == 0] for (x0, y0), (x1, y1) in f if x0 == x1 or y0 == y1] for item in sublist]).items() if v >= 2]))
|
|
print(sum([1 for k, v in Counter([item for sublist in [[(x, y) for x in range(min(x0, x1), max(x0, x1) + 1) for y in range(min(y0, y1), max(y0, y1) + 1) if ((x - x0) * (y1 - y0) - (y - y0) * (x1 - x0)) == 0] for (x0, y0), (x1, y1) in f] for item in sublist]).items() if v >= 2])) |