Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Input: lines like "<token>: <token> <token> ..."
- # Output: number of paths from "you" to "out"
- import functools
- @functools.cache
- def number_paths(k):
- if k == "out":
- return 1
- t = 0
- for v in paths[k]:
- t += number_paths(v)
- 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("you"))
Advertisement
Add Comment
Please, Sign In to add comment