Compare commits
No commits in common. 'ab0cfb8f80913e0f514089b8406b4c79d6ebdaf7' and 'a30495380541596af1bee91c0bafd66cfa51cfbc' have entirely different histories.
ab0cfb8f80
...
a304953805
3 changed files with 43 additions and 52 deletions
@ -1,41 +0,0 @@ |
||||
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 |
||||
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 |
||||
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 |
||||
if gridAll[l[0][0]+i*xDir][l[0][1]+i*yDir] == 2: |
||||
overlapsAll += 1 |
||||
|
||||
|
||||
print(overlaps) |
||||
print(overlapsAll) |
@ -0,0 +1,27 @@ |
||||
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)] |
||||
|
||||
for l in lines: |
||||
if l[0][0] == l[1][0]: |
||||
if l[0][1] > l[1][1]: |
||||
l = (l[1],l[0]) |
||||
for i in range(l[0][1], l[1][1]+1): |
||||
grid[l[0][0]][i] += 1 |
||||
if l[0][1] == l[1][1]: |
||||
if l[0][0] > l[1][0]: |
||||
l = (l[1],l[0]) |
||||
for i in range(l[0][0], l[1][0]+1): |
||||
grid[i][l[0][1]] += 1 |
||||
|
||||
overlaps=0 |
||||
for m in grid: |
||||
for n in m: |
||||
if n > 1: |
||||
overlaps += 1 |
||||
print(overlaps) |
Loading…
Reference in new issue