Skip to content

Instantly share code, notes, and snippets.

@ioncodes
Last active February 9, 2018 16:20
Show Gist options
  • Save ioncodes/185ce7200a000ca6c015ca3cc768b593 to your computer and use it in GitHub Desktop.
Save ioncodes/185ce7200a000ca6c015ca3cc768b593 to your computer and use it in GitHub Desktop.
combination gen for mortoray
#[derive(Debug)]
struct Pair {
pub x: usize,
pub y: usize,
}
fn combs(v: Vec<usize>) -> Vec<Pair> {
let mut t = &v[1..];
let mut combinations = Vec::<Pair>::new();
let last = match v.last() {
Some(last_val) => last_val,
None => &0,
};
for i in v.iter() {
for _ in t.iter().map(|e| combinations.push(Pair { x: *i, y: *e })) {}
if last != i {
t = &t[1..];
}
}
combinations
}
fn main() {
println!("{:?}", combs(vec![1, 2, 3, 4, 5, 6]));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment