jour 23
This commit is contained in:
75
day23.py
Normal file
75
day23.py
Normal file
@ -0,0 +1,75 @@
|
||||
import networkx as nx
|
||||
|
||||
|
||||
l = ["kh-tc",
|
||||
"qp-kh",
|
||||
"de-cg",
|
||||
"ka-co",
|
||||
"yn-aq",
|
||||
"qp-ub",
|
||||
"cg-tb",
|
||||
"vc-aq",
|
||||
"tb-ka",
|
||||
"wh-tc",
|
||||
"yn-cg",
|
||||
"kh-ub",
|
||||
"ta-co",
|
||||
"de-co",
|
||||
"tc-td",
|
||||
"tb-wq",
|
||||
"wh-td",
|
||||
"ta-ka",
|
||||
"td-qp",
|
||||
"aq-cg",
|
||||
"wq-ub",
|
||||
"ub-vc",
|
||||
"de-ta",
|
||||
"wq-aq",
|
||||
"wq-vc",
|
||||
"wh-yn",
|
||||
"ka-de",
|
||||
"kh-ta",
|
||||
"co-tc",
|
||||
"wh-qp",
|
||||
"tb-vc",
|
||||
"td-yn"]
|
||||
|
||||
with open('day23.txt') as f:
|
||||
l = f.read().splitlines()
|
||||
|
||||
# nodes = []
|
||||
G = nx.Graph()
|
||||
cycles = []
|
||||
|
||||
for line in l:
|
||||
line = line.split("-")
|
||||
for n in line:
|
||||
if n not in list(G.nodes):
|
||||
G.add_node(n)
|
||||
G.add_edge(line[0],line[1])
|
||||
print(list(G.nodes))
|
||||
|
||||
cnt = 0
|
||||
largest = []
|
||||
for c in nx.clique.enumerate_all_cliques(G):
|
||||
# print(c)
|
||||
if len(c)==3:
|
||||
for comp in c:
|
||||
# print(comp)
|
||||
if comp[0] == "t":
|
||||
# print("True")
|
||||
cnt += 1
|
||||
break
|
||||
if len(c) > len(largest):
|
||||
largest = c
|
||||
print(cnt)
|
||||
print(largest)
|
||||
print(sorted(largest))
|
||||
password = ""
|
||||
for c in sorted(largest):
|
||||
password = password+c+","
|
||||
print(password)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user