blob: 86af8aa4eae5a5a5f1743f3288574179e5313e0e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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);
|