Function dpss::dp::sequence_matcher
source · [−]pub fn sequence_matcher(
key: &mut Vec<i32>,
targets: &mut Vec<i32>,
max_target_length: usize
) -> Vec<Vec<(i32, Vec<i32>)>>Expand description
Finds the integers from two vectors that sum to the same value.
This method assumes that the two vectors have One-to-Many relationships.
Each integer of the key vector corresponds to the multiple integers of the value vector.
Arguments
key- An array.targets- An array.max_length- The maximum length of combinations of the answer.
Example
use dpss::dp::sequence_matcher;
let answer = sequence_matcher(&mut vec![3, 5, 7], &mut vec![1, 5, -3, 4, 5, 3], 4);
assert_eq!(answer, vec![
vec![
(3, vec![3]),
(5, vec![5]),
(7, vec![5, 4, -3, 1]),
],
vec![
(3, vec![3]),
(5, vec![4, 1]),
(7, vec![5, 5, -3]),
],
vec![
(3, vec![5, -3, 1]),
(5, vec![5]),
(7, vec![3, 4]),
],
]);
let answer_unchanged: Vec<Vec<(i32, Vec<i32>)>> = Vec::new();
let answer = sequence_matcher(&mut vec![10, 20], &mut vec![9, 21], 1);
assert_eq!(answer, answer_unchanged);