Expand description
ยงReactor
The devices form a directed acyclic graph since any cycle would imply infinite possible paths. A recursive depth-first search will enumerate every possible path between two nodes. The number of paths from each node to the destination is cached since we only need the total count of paths and not the actual distinct different paths.
As a performance optimization, each 3-letter node is converted into an index so that a much
faster array lookup can be used instead of a HashMap.
Functionsยง
- dfs ๐
- parse
- Build the graph.
- part1
- part2
- Split the route into 3 segments. The answer is the number of paths in each segment multiplied by each other. In the actual input, one of these paths will not be possible and will have zero total count.
- paths ๐
- to_
index ๐ - Convert 3-letter name to index.
Type Aliasesยง
- Input ๐