diff --git a/src/bin/solve/simple.rs b/src/bin/solve/simple.rs index a71b947..aa7f996 100644 --- a/src/bin/solve/simple.rs +++ b/src/bin/solve/simple.rs @@ -7,7 +7,7 @@ use libpt::log::*; use wordle_analyzer::game::response::GuessResponse; -use wordle_analyzer::solve::{stupid, BuiltinSolverNames, NaiveSolver, Solver, StupidSolver}; +use wordle_analyzer::solve::{BuiltinSolverNames, Solver}; use wordle_analyzer::wlist::builtin::BuiltinWList; use wordle_analyzer::wlist::word::Word; use wordle_analyzer::{self, game}; diff --git a/src/wlist/mod.rs b/src/wlist/mod.rs index 6f545e6..2cd029c 100644 --- a/src/wlist/mod.rs +++ b/src/wlist/mod.rs @@ -47,7 +47,7 @@ pub trait WordList: Clone + std::fmt::Debug + Default { WordMap::from(hm) } fn get_word(&self, word: &Word) -> Option; - fn letter_frequency(&self) -> WordMap { + fn letter_frequency(&self) -> HashMap { // PERF: this function has complexity O(n²)! let mut cmap: HashMap = HashMap::new(); // count the chars in each word @@ -58,8 +58,8 @@ pub trait WordList: Clone + std::fmt::Debug + Default { } } } - // make all chars to strings - let cmap: HashMap = cmap.into_iter().map(|p| (p.0.to_string(), p.1)).collect(); - WordMap::from_absolute(cmap) + // convert to relative frequency + let n: f64 = cmap.keys().len() as f64; + cmap.into_iter().map(|p| (p.0, p.1 as f64 / n)).collect() } } diff --git a/src/wlist/word.rs b/src/wlist/word.rs index 785f4ea..2385a2e 100644 --- a/src/wlist/word.rs +++ b/src/wlist/word.rs @@ -103,3 +103,9 @@ impl From> for WordMap { Self { inner: value } } } + +impl From for HashMap{ + fn from(value: WordMap) -> Self { + value.inner + } +}