Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created March 19, 2018 06:42
Show Gist options
  • Save rust-play/bb43614927d3bb8997ff61cef40a68df to your computer and use it in GitHub Desktop.
Save rust-play/bb43614927d3bb8997ff61cef40a68df to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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