-
Notifications
You must be signed in to change notification settings - Fork 0
/
day6.1.py
64 lines (53 loc) · 1.39 KB
/
day6.1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
infile = open("day6.in", "r")
# infile = open("test.in", "r")
inString = infile.read()
inList = inString.splitlines()
xMin = 0
xMax = 0
yMin = 0
yMax = 0
nodeDict = {}
for node in inList:
x = int(node.split(',')[0])
y = int(node.split(',')[1])
nodeDict[(x,y)] = [False]
if x < xMin:
xMin = x
if x > xMax:
xMax = x
if y < yMin:
yMin = y
if y > yMax:
yMax = y
def findClosestNode(X,Y, nodeDict=nodeDict, xMin=xMin, xMax=xMax, yMin=yMin, yMax=yMax):
min = xMax-xMin+yMax-yMin
closeNode = []
for node in nodeDict:
distance = abs(node[0]-X)+abs(node[1]-Y)
if distance < min:
min = distance
closeNode = [node]
elif distance == min:
closeNode.append(node)
return(closeNode)
for i in range(xMin,xMax+1):
for j in range(yMin,yMax+1):
edge = False
closeNodes = findClosestNode(i,j)
if len(closeNodes) > 1:
continue
if (i == xMin or i == xMax or j == yMin or j == yMax):
edge = True
for node in closeNodes:
nodeDict[node].append((i,j))
if not nodeDict[node][0] and edge:
nodeDict[node][0]=edge
maxArea = 0
for node in nodeDict:
if nodeDict[node][0]:
continue
area = len(nodeDict[node])-1
if area > maxArea:
maxArea = area
# print(nodeDict)
print(maxArea)