aoc2021/d05/d05_1.py

44 lines
605 B
Python
Raw Permalink Normal View History

2021-12-07 23:42:19 +00:00
import sys
W = 1000
H = 1500
grid = [ [ 0 for _ in range(W) ] for _ in range(H) ]
#print(grid)
L = eval(sys.stdin.read())
#print(L)
def printgrid():
for row in grid:
print("".join(map(str,row)))
printgrid()
v=0
h=0
n=0
for ((x1,y1),(x2,y2)) in L:
print((x1,y1),(x2,y2))
if x1 == x2:
v+=1
(y1, y2) = (min(y1,y2), max(y1,y2))
for y in range(y1, y2+1):
grid[x1][y]+=1
if grid[x1][y]==2:
n+=1
elif y1 == y2:
h+=1
(x1, x2) = (min(x1,x2), max(x1,x2))
for x in range(x1, x2+1):
grid[x][y1]+=1
if grid[x][y1]==2:
n+=1
printgrid()
print(n, v, h, v+h)
# 1116 too low