From de308443f4ed4e12cd18578af09b93d7d01e2a84 Mon Sep 17 00:00:00 2001 From: bthink Date: Fri, 12 Dec 2025 12:42:43 +0100 Subject: final week of 2025 --- 2025/aoc2025-d11.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 2025/aoc2025-d11.py (limited to '2025/aoc2025-d11.py') diff --git a/2025/aoc2025-d11.py b/2025/aoc2025-d11.py new file mode 100644 index 0000000..86af8aa --- /dev/null +++ b/2025/aoc2025-d11.py @@ -0,0 +1,35 @@ +#advent of code 2025 +#day 11 +#more reading for later, maybe there's a different algo than dfs/bfs +# https://en.wikipedia.org/wiki/Directed_acyclic_graph +#no idea why my format doesn't work +#below is format which was shamelessly stolen from someone else +#don't sue me +#will rewrite it later as a product +#possible paths svr-fft; possible paths fft-dac; possible paths dac-out + +from functools import cache + +connections=dict(); +PuzzleInput=open("11.in","r"); +for l in PuzzleInput: + vertex,nodes=l.strip().split(": "); + if vertex not in connections: connections[vertex]=set(); + connections[vertex].update(nodes.split()) + +@cache +def findpaths(pos,fft,dac): + if pos=="out": + return 1*fft*dac; + score=0; + fft_=fft or pos=="fft"; + dac_=dac or pos=="dac"; + for con in connections[pos]: + score+=findpaths(con,fft_,dac_); + return score; + +part1=findpaths("you",True,True); +part2=findpaths("svr",False,False); + +print("part 1 =",part1); +print("part 2 =",part2); -- cgit v1.2.3