Guest User

Untitled

a guest
Dec 10th, 2025
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. # Input: lines like "<token>: <token> <token> ..."
  2. # Output: number of paths from "you" to "out"
  3.  
  4. import functools
  5.  
  6. @functools.cache
  7. def number_paths(k):
  8.   if k == "out":
  9.     return 1
  10.   t = 0
  11.   for v in paths[k]:
  12.     t += number_paths(v)
  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("you"))
  23.  
Advertisement
Add Comment
Please, Sign In to add comment