Created
March 19, 2018 06:42
-
-
Save rust-play/bb43614927d3bb8997ff61cef40a68df to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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::collections::HashSet; | |
use std::str::FromStr; | |
fn main() { | |
let alphabets = String::from_str("ABCDEFGHIJKLMNOPQRSTUVWXYZ").unwrap(); | |
let alpha_set: HashSet<_> = alphabets.split("").filter(|x| x.len() != 0).collect(); | |
let keyword = String::from_str("SECRET").unwrap(); | |
let keyword_set: HashSet<_> = keyword.split("").filter(|x| x.len() != 0).collect(); | |
let diffset: HashSet<_> = alpha_set.difference(&keyword_set).collect(); | |
let mut rem_alphas: Vec<_> = diffset.clone().into_iter().collect(); | |
rem_alphas.sort_by_key(|&x| alphabets.find(x)); | |
let mut keyword_sort: Vec<_> = keyword_set.clone().into_iter().collect(); | |
keyword_sort.sort_by_key(|&x| keyword.find(x)); | |
println!("{:?}", rem_alphas); | |
println!("{:?}", keyword_sort); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment