Guest User

Untitled

a guest
Dec 10th, 2025
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. # Input: lines like "<token>: <token> <token> ..."
  2. # Output: number of paths from "svr" to "out" that go through "dac" and "fft"
  3.  
  4. import functools
  5.  
  6. @functools.cache
  7. def number_paths(k, seen_dac, seen_fft):
  8.   if k == "out":
  9.     return 1 if (seen_dac and seen_fft) else 0
  10.   t = 0
  11.   for v in paths[k]:
  12.     t += number_paths(v, seen_dac or (k == "dac"), seen_fft or (k == "fft"))
  13.   return t
  14.  
  15. paths = {}
  16.  
  17. file = open("11_input.txt", "r")
  18. for line in file:
  19.   line = line.replace("\n", "")
  20.   chunks = line.split(": ")
  21.   paths[chunks[0]] = chunks[1].split(" ")
  22. print (number_paths("svr", False, False))
  23.  
Advertisement
Add Comment
Please, Sign In to add comment