Created
January 10, 2023 16:57
-
-
Save Ad1n/063c711923cb54331a7f606f9a040c16 to your computer and use it in GitHub Desktop.
All combinations between unknown counts of vectors, ordered by exposed list of vectors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fn main() { | |
| let mut v: Vec<Vec<&str>> = Vec::new(); | |
| v.push(["1", "2"].to_vec()); | |
| v.push(["3", "4", "5"].to_vec()); | |
| v.push(["6", "7"].to_vec()); | |
| let mut acc = Vec::new(); | |
| v.iter() | |
| .map(|el| { | |
| if acc.is_empty() { | |
| for i in el { | |
| println!("empty"); | |
| acc.push(Vec::from([i])) | |
| } | |
| } else { | |
| let temp = acc.clone(); | |
| acc.clear(); | |
| println!("any"); | |
| for el1 in temp { | |
| for el2 in el { | |
| let mut t_v = el1.clone(); | |
| t_v.push(el2); | |
| acc.push(t_v); | |
| } | |
| } | |
| } | |
| }) | |
| .collect::<Vec<_>>(); | |
| println!("{:?}", acc); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment