Attempt at error handling, vendor dict

This commit is contained in:
Luke Hubmayer-Werner 2022-02-04 12:35:22 +10:30
parent d2cc2b850a
commit 95eff8cfb8
2 changed files with 102781 additions and 3 deletions

View File

@ -52,8 +52,12 @@ fn generate_wordcache(words: Vec<String>) -> HashMap<String, Vec<String>> {
fn hs2str(hs: &HashSet<char>) -> String { fn hs2str(hs: &HashSet<char>) -> String {
let mut chars: Vec<char> = hs.iter().cloned().collect(); let mut chars: Vec<char> = hs.iter().cloned().collect();
if chars.is_empty() {
"".to_string()
} else {
chars.sort_unstable(); chars.sort_unstable();
chars.iter().collect() chars.iter().collect()
}
} }
fn simulate(guess: &str, solution: &str, wordcache: &HashMap<String, Vec<String>>) -> Vec<String> { fn simulate(guess: &str, solution: &str, wordcache: &HashMap<String, Vec<String>>) -> Vec<String> {
@ -100,7 +104,7 @@ fn find_worstcase(word: &str, wordcache: &HashMap<String, Vec<String>>) -> Strin
fn main() { fn main() {
fs::write("test.txt", ["test1", "test2", "test3"].join("\n")).expect("Failed to write output"); fs::write("test.txt", ["test1", "test2", "test3"].join("\n")).expect("Failed to write output");
let words = load_dictionary("/usr/share/dict/words"); let words = load_dictionary("words");
println!("Hello, world! {} words in dict", words.len()); println!("Hello, world! {} words in dict", words.len());
let wordcache = generate_wordcache(words); let wordcache = generate_wordcache(words);
//let sr = simulate(&wordcache[""][0], &wordcache[""][5000], &wordcache); //let sr = simulate(&wordcache[""][0], &wordcache[""][5000], &wordcache);

102774
words Normal file

File diff suppressed because it is too large Load Diff