pub fn garage(
initial: Vec<i32>,
final_state: Vec<i32>,
) -> Result<(i32, Vec<Vec<i32>>), String>Expand description
Find the minimum swaps to rearrange a parking lot from initial to final state.
A tuple of (number_of_steps, sequence_of_states) showing each intermediate arrangement.
ยงExamples
Basic usage:
let result = algorithmz::array::garage(vec![1,2,3,0,4],vec![0,3,2,1,4]).unwrap();
assert_eq!(result,(4,vec![vec![0, 2, 3, 1, 4], vec![2, 0, 3, 1, 4], vec![2, 3, 0, 1, 4], vec![0, 3, 2, 1, 4]]));Match example:
use algorithmz::array::garage;
let start = vec![1, 2, 3, 0, 4];
let end = vec![0, 3, 2, 1, 4];
match garage(start,end) {
Ok((moves,steps)) => println!("The moves: {} and steps: {:?}",moves, steps),
Err(e) => eprintln!("The error was: {}",e),
}