Day23 almost done :(

This commit is contained in:
Daniel Weber 2024-12-23 06:46:23 -05:00
parent c682b07075
commit 02f61c5687

64
2024/day23/main.py Normal file
View File

@ -0,0 +1,64 @@
import sys
import os
sys.path.insert(1, os.path.abspath('../../'))
from python_tools.aoc_utils import *
import collections as C
def part_one(g):
lan = set()
for i in g:
for key1 in g[i]:
for key2 in g[i]:
if key1 != key2:
if key2 in g[key1] and key1 in g[key2]:
pl = [i,key1, key2]
pl.sort()
lan.add(tuple(pl))
p1 = 0
for i in lan:
for j in i:
if j[0] == "t":
p1 += 1
break
print("P1: ", p1)
def part_two(g):
lan = set()
for i in g:
temp_lan = set([i])
for key1 in g[i]:
pc = True
for j in temp_lan:
if j not in g[key1]:
pc = False
if pc:
temp_lan.add(key1)
x = list(temp_lan)
x.sort()
lan.add(','.join(x))
p2 = 0
max_val = []
for i in lan:
if len(i) > p2:
p2 = len(i)
max_val = i
print("P2: ", max_val)
def main():
contents = file2list("input.txt")
g = C.defaultdict(set)
for i in contents:
x = i.split('-')
g[x[0]].add(x[1])
g[x[1]].add(x[0])
part_one(g)
part_two(g)
if __name__ == "__main__":
main()