Created
March 5, 2020 22:56
-
-
Save hexjelly/4048c100789ed1f374b4bb2c70cbe53f to your computer and use it in GitHub Desktop.
This file contains 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
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