diff options
| author | bthink <bthink@fake.com> | 2025-12-12 12:42:43 +0100 |
|---|---|---|
| committer | bthink <bthink@fake.com> | 2025-12-12 12:42:43 +0100 |
| commit | de308443f4ed4e12cd18578af09b93d7d01e2a84 (patch) | |
| tree | e8977d445fe6a86b45dfc8bec8aa46b1fddde76c /2025/aoc2025-d11.py | |
| parent | ed395fe7a7fd68f6db4ea94de8fdcdcb0fac5179 (diff) | |
Diffstat (limited to '2025/aoc2025-d11.py')
| -rw-r--r-- | 2025/aoc2025-d11.py | 35 |
1 files changed, 35 insertions, 0 deletions
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); |
