55 lines
1.5 KiB
Python
55 lines
1.5 KiB
Python
with open(r'day9/input.txt', 'r') as input:
|
|
lines = list(map(lambda x: list(map(lambda y: int(y),x.split(','))),input.read().split('\n')[:-1]))
|
|
|
|
def surface(a,b):
|
|
return (abs(a[0]-b[0])+1)*(abs(a[1]-b[1])+1)
|
|
|
|
inner = set()
|
|
|
|
for i in range(len(lines)):
|
|
j = (i+1)%len(lines)
|
|
if lines[i][0] == lines[j][0]:
|
|
sign = 1 if lines[i][1] <= lines[j][1] else -1
|
|
for x in range(lines[i][1],lines[j][1],sign):
|
|
inner.add((lines[i][0],x))
|
|
else:
|
|
sign = 1 if lines[i][0] <= lines[j][0] else -1
|
|
for x in range(lines[i][0],lines[j][0],sign):
|
|
inner.add((x,lines[i][1]))
|
|
|
|
if lines[0][0] == lines[1][0]:
|
|
init = (lines[0][0]-1,lines[0][1]+1)
|
|
else:
|
|
init = (lines[0][0]+1,lines[0][1]+1)
|
|
|
|
print(init)
|
|
|
|
L=[init]
|
|
neigh = [[-1,0],[-1,-1],[0,-1],[1,0],[0,1],[1,1],[-1,1],[1,-1]]
|
|
while len(L):
|
|
sommet = L.pop(0)
|
|
if sommet not in inner:
|
|
inner.add(sommet)
|
|
for nei in neigh:
|
|
new = (sommet[0]+nei[0],sommet[1]+nei[1])
|
|
if new not in inner and new not in L:
|
|
L.append(new)
|
|
|
|
print("init done")
|
|
|
|
def is_inside(a,b):
|
|
for i in range(min(a[0],b[0]),max(a[0],b[0])+1):
|
|
for j in range(min(a[1],b[1]),max(a[1],b[1])+1):
|
|
if (i,j) not in inner:
|
|
return False
|
|
return True
|
|
|
|
best = surface(lines[0],lines[1])
|
|
|
|
for i in range(len(lines)):
|
|
for j in range(i):
|
|
if is_inside(lines[i],lines[j]):
|
|
best = max(best,surface(lines[i],lines[j]))
|
|
|
|
print(best)
|
|
|