Skip to content

Instantly share code, notes, and snippets.

@hexjelly
Created March 5, 2020 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hexjelly/4048c100789ed1f374b4bb2c70cbe53f to your computer and use it in GitHub Desktop.
Save hexjelly/4048c100789ed1f374b4bb2c70cbe53f to your computer and use it in GitHub Desktop.
use std::str;
use std::collections::HashSet;
use permutohedron::Heap;
fn main() {
let original_data = b"abcdefghi".to_vec();
let mut data = original_data.clone();
let heap = Heap::new(&mut data);
let mut permutations = Vec::new();
for data in heap {
let s = str::from_utf8(&data).unwrap().to_owned();
permutations.push(s);
}
println!("{:?}", permutations.len());
let filtered_permutations = permutations.iter().filter(|s| {
!original_data
.iter()
.zip(s.as_bytes())
.any(|(orig_c, c)| orig_c == c)
}).collect::<HashSet<_>>();
println!("{:?}", filtered_permutations.len())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment