streamlined 5 even more

kwout 2 years ago
parent 8a808d947d
commit 8800495b02
  1. 24
      2021/day5/5.py

@ -15,25 +15,21 @@ for l in lines:
yDir = 0 yDir = 0
if l[0][0] > l[1][0]: if l[0][0] > l[1][0]:
xDir = -1 xDir = -1
if l[0][0] < l[1][0]: elif l[0][0] < l[1][0]:
xDir = 1 xDir = 1
if l[0][1] > l[1][1]: if l[0][1] > l[1][1]:
yDir = -1 yDir = -1
if l[0][1] < l[1][1]: elif l[0][1] < l[1][1]:
yDir = 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
for i in range(0, max([abs(l[1][0]-l[0][0]),abs(l[1][1]-l[0][1])])+1): for i in range(0, max([abs(l[1][0]-l[0][0]),abs(l[1][1]-l[0][1])])+1):
gridAll[l[0][0]+i*xDir][l[0][1]+i*yDir] += 1 x = l[0][0]+i*xDir
if gridAll[l[0][0]+i*xDir][l[0][1]+i*yDir] == 2: 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 overlapsAll += 1

Loading…
Cancel
Save