-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday23pt2.py
44 lines (30 loc) · 1 KB
/
day23pt2.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
day23input = [line.strip().split('-') for line in open('day23example.txt')]
# day23input = [line.strip().split('-') for line in open('day23input.txt')]
# print(day23input)
conns = dict()
def get_conns():
for x, y in day23input:
if x not in conns: conns[x] = set()
if y not in conns: conns[y] = set()
conns[x].add(y)
conns[y].add(x)
closed_set = set()
def search(node, frontier):
closed_set_key = tuple(sorted(frontier))
if closed_set_key in closed_set: return
closed_set.add(closed_set_key)
for neighbor in conns[node]:
if neighbor in frontier: continue
# if its a child of every frontier item
if all(neighbor in conns[front] for front in frontier):
# insert neighbor
search(neighbor, {*frontier, neighbor})
get_conns()
# print(conns)
for x in conns:
search(x, {x})
print(closed_set, len(closed_set))
print(','.join(max(closed_set, key=len)))
# print('Triangles')
# print(triangles)
# print(len([triangle for triangle in triangles if any(tri.startswith('t') for tri in triangle)]))