Last active
February 9, 2018 16:20
-
-
Save ioncodes/185ce7200a000ca6c015ca3cc768b593 to your computer and use it in GitHub Desktop.
combination gen for mortoray
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
#[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