You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

34 lines
748 B

lines = []
for l in open("input.txt", 'r').read().splitlines():
p = l.split(" -> ")
q = []
q.append(p[0].split(","))
q.append(p[1].split(","))
lines.append([[int(q[0][0]),int(q[0][1])],[int(q[1][0]), int(q[1][1])]])
grid = [[0 for i in range(1000)] for j in range(1000)]
overlaps = 0
for l in lines:
xDir = 0
yDir = 0
if l[0][0] > l[1][0]:
xDir = -1
if l[0][0] < l[1][0]:
xDir = 1
if l[0][1] > l[1][1]:
yDir = -1
if l[0][1] < l[1][1]:
yDir = 1
if xDir == 0:
for i in range(l[0][1],l[1][1]+yDir,yDir):
grid[l[0][0]][i] += 1
if grid[l[0][0]][i] == 2:
overlaps += 1
if yDir == 0:
for i in range(l[0][0],l[1][0]+xDir,xDir):
grid[i][l[0][1]] += 1
if grid[i][l[0][1]] == 2:
overlaps += 1
print(overlaps)