Function pathfinding::directed::count_paths::count_paths
source · pub fn count_paths<T, FN, IN, FS>(
start: T,
successors: FN,
success: FS
) -> usize
Expand description
Count the total number of possible paths to reach a destination. There must be no loops in the graph, or the function will overflow its stack.
§Example
On a 8x8 board, find the total paths from the bottom-left square to the top-right square.
use pathfinding::prelude::count_paths;
let n = count_paths(
(0, 0),
|&(x, y)| {
[(x + 1, y), (x, y + 1)]
.into_iter()
.filter(|&(x, y)| x < 8 && y < 8)
},
|&c| c == (7, 7),
);
assert_eq!(n, 3432);