Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Input: lines like "<token>: <token> <token> ..."
- # Output: number of paths from "svr" to "out" that go through "dac" and "fft"
- import functools
- @functools.cache
- def number_paths(k, seen_dac, seen_fft):
- if k == "out":
- return 1 if (seen_dac and seen_fft) else 0
- t = 0
- for v in paths[k]:
- t += number_paths(v, seen_dac or (k == "dac"), seen_fft or (k == "fft"))
- return t
- paths = {}
- file = open("11_input.txt", "r")
- for line in file:
- line = line.replace("\n", "")
- chunks = line.split(": ")
- paths[chunks[0]] = chunks[1].split(" ")
- print (number_paths("svr", False, False))
Advertisement
Add Comment
Please, Sign In to add comment