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.
37 lines
848 B
37 lines
848 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)]
|
|
gridAll = [[0 for i in range(1000)] for j in range(1000)]
|
|
overlaps = 0
|
|
overlapsAll = 0
|
|
|
|
for l in lines:
|
|
xDir = 0
|
|
yDir = 0
|
|
if l[0][0] > l[1][0]:
|
|
xDir = -1
|
|
elif l[0][0] < l[1][0]:
|
|
xDir = 1
|
|
if l[0][1] > l[1][1]:
|
|
yDir = -1
|
|
elif l[0][1] < l[1][1]:
|
|
yDir = 1
|
|
for i in range(0, max([abs(l[1][0]-l[0][0]),abs(l[1][1]-l[0][1])])+1):
|
|
x = l[0][0]+i*xDir
|
|
y = l[0][1]+i*yDir
|
|
if xDir == 0 or yDir == 0:
|
|
grid[x][y] +=1
|
|
if grid[x][y] == 2:
|
|
overlaps +=1
|
|
gridAll[x][y] += 1
|
|
if gridAll[x][y] == 2:
|
|
overlapsAll += 1
|
|
|
|
|
|
print(overlaps)
|
|
print(overlapsAll)
|
|
|