Skip to content

Instantly share code, notes, and snippets.

@CrystalGamma
Created March 27, 2016 14:15
Show Gist options
  • Save CrystalGamma/099f48247ab78a4d6aea to your computer and use it in GitHub Desktop.
Save CrystalGamma/099f48247ab78a4d6aea to your computer and use it in GitHub Desktop.
Qwerty ⇔ Neo dictionary overlapp checker
use std::io::prelude::*;
use std::collections::{HashMap, BTreeSet};
use std::fs::File;
use std::io::BufReader;
fn main() {
let trans: HashMap<_, _> = [
('q', 'x'), ('w', 'v'), ('e', 'l'), ('r', 'c'), ('t', 'w'), ('y', 'k'), ('u', 'h'), ('i', 'g'), ('o', 'f'), ('p', 'q'),
('a', 'u'), ('s', 'i'), ('d', 'a'), ('f', 'e'), ('g', 'o'), ('h', 's'), ('j', 'n'), ('k', 'r'), ('l', 't'), // whatever is right of L => 'd', L+2 => 'y'
('v', 'p'), ('b', 'z'), ('n', 'b'), ('m', 'm') // 'z' => 'ü', '/' => 'j'
].iter().cloned().collect();
let words: BTreeSet<_> = BufReader::new(File::open("/usr/share/dict/american-english").unwrap()) // my system is in German, so I have to be specific about the language
.lines().map(Result::unwrap).filter_map(|s| {
let w = s.trim_right();
if w.chars().all(
|c| c != 'd' && c != 'y' && c != 'z' && c != 'j'
&& c != 'D' && c != 'Y' && c != 'Z' && c != 'J'
) {Some(w.to_lowercase())} else {None}
}).collect();
for word in &words {
if let Some(converted) = word.chars().map(|c| trans.get(&c).cloned()).collect::<Option<String>>() {
if words.contains(&converted) {
println!("{} ⇒ {}", word, converted);
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment