powered by
Finds the shortest path between two permutation states using bidirectional breadth-first search. Expands from both the start and goal states simultaneously, meeting in the middle.
bidirectional_bfs(n, state1, state2, max_level, moves, k)
Character vector of operations forming the shortest path, or NULL if no path found within max_level
Integer, size of the permutation
Integer vector, start state
Integer vector, goal state
Integer, maximum BFS depth in each direction
Character vector, allowed operations (e.g., c("1", "2", "3"))
Integer, parameter for reverse operations
# Find path between two small states path <- bidirectional_bfs(5, 1:5, c(2, 3, 4, 5, 1), max_level = 5, moves = c("1", "2", "3"), k = 3) path
Run the code above in your browser using DataLab