From 02f61c5687e223664484acbfdc1b3a5c9997ad42 Mon Sep 17 00:00:00 2001 From: Daniel Weber Date: Mon, 23 Dec 2024 06:46:23 -0500 Subject: [PATCH] Day23 almost done :( --- 2024/day23/main.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 2024/day23/main.py diff --git a/2024/day23/main.py b/2024/day23/main.py new file mode 100644 index 0000000..1ce03ff --- /dev/null +++ b/2024/day23/main.py @@ -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() +