This commit is contained in:
Stefan Harmuth 2024-12-23 06:37:18 +01:00
parent a0ff8eb0b9
commit 9e1db2a109
4 changed files with 3484 additions and 0 deletions

1
.gitignore vendored
View File

@ -128,6 +128,7 @@ venv/
ENV/
env.bak/
venv.bak/
venv_pypy/
# Spyder project settings
.spyderproject

71
day23.py Normal file
View File

@ -0,0 +1,71 @@
from black.trans import defaultdict
from tools.aoc import AOCDay
from typing import Any
class Day(AOCDay):
inputs = [
[
(7, "input23_test"),
(1411, "input23"),
],
[
("co,de,ka,ta", "input23_test"),
("aq,bn,ch,dt,gu,ow,pk,qy,tv,us,yx,zg,zu", "input23"),
],
]
def parse_input(self) -> dict[str, set]:
conns = defaultdict(set)
for line in self.getInput():
a, b = line.split("-")
conns[a].add(b)
conns[b].add(a)
return conns
def part1(self) -> Any:
conns = self.parse_input()
sets = set()
for comp in conns:
if not comp.startswith("t"):
continue
for a in conns[comp]:
for b in conns[comp]:
if a == b:
continue
if b in conns[a]:
sets.add(",".join(sorted([comp, a, b])))
return len(sets)
def part2(self) -> Any:
conns = self.parse_input()
best = set()
for comp in conns:
lan = {comp}
for a in conns[comp]:
for b in conns[comp]:
if a == b:
continue
if b in conns[a]:
lan.add(a)
lan.add(b)
good = True
for a in lan:
for b in lan:
if a != b and a not in conns[b]:
good = False
if good and len(lan) > len(best):
best = lan
return ",".join(sorted(best))
if __name__ == "__main__":
day = Day(2024, 23)
day.run(verbose=True)

3380
inputs/input23 Normal file

File diff suppressed because it is too large Load Diff

32
inputs/input23_test Normal file
View File

@ -0,0 +1,32 @@
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