Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. fn f(v : &[&[u32]], cur: &mut Vec<u32>, r : &mut Vec<Vec<u32>>){
  2. if v.is_empty() {
  3. r.push(cur.clone());
  4. return;
  5. }
  6.  
  7. let first = v[0];
  8. let others = &v[1..];
  9. for &x in first.iter() {
  10. cur.push(x);
  11. f(others,cur,r);
  12. cur.pop();
  13. }
  14. }
  15.  
  16. fn g(v : &[&[u32]]) -> Vec<Vec<u32>> {
  17. let mut cur = vec![];
  18. let mut ret = vec![];
  19. f(v,&mut cur, &mut ret);
  20. ret
  21. }
  22.  
  23. fn main() {
  24. let v = [&[1,2,3,4][..],&[5,6,7,8][..]];
  25.  
  26. println!("FIRST {:#?}",g(&v));
  27.  
  28. let v = [&[1,2,3,4][..],&[5,6,7,8][..],&[9,10,11,12][..]];
  29.  
  30. println!("SECOND {:#?}",g(&v));
  31.  
  32. let v = [&[1,2,3,4][..],&[5,6,7,8][..],&[9,10,11,12][..],&[13,14,15,16][..]];
  33.  
  34. println!("THIRD {:#?}",g(&v));
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement