generated from PlexSheep/rs-base
Merge branch 'master' of https://git.cscherr.de/PlexSheep/wordle-analyzer
This commit is contained in:
commit
8afede35b6
|
@ -7,7 +7,7 @@ use libpt::log::*;
|
||||||
|
|
||||||
use wordle_analyzer::game::response::GuessResponse;
|
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::builtin::BuiltinWList;
|
||||||
use wordle_analyzer::wlist::word::Word;
|
use wordle_analyzer::wlist::word::Word;
|
||||||
use wordle_analyzer::{self, game};
|
use wordle_analyzer::{self, game};
|
||||||
|
|
|
@ -47,7 +47,7 @@ pub trait WordList: Clone + std::fmt::Debug + Default {
|
||||||
WordMap::from(hm)
|
WordMap::from(hm)
|
||||||
}
|
}
|
||||||
fn get_word(&self, word: &Word) -> Option<WordData>;
|
fn get_word(&self, word: &Word) -> Option<WordData>;
|
||||||
fn letter_frequency(&self) -> WordMap {
|
fn letter_frequency(&self) -> HashMap<char, Frequency> {
|
||||||
// PERF: this function has complexity O(n²)!
|
// PERF: this function has complexity O(n²)!
|
||||||
let mut cmap: HashMap<char, usize> = HashMap::new();
|
let mut cmap: HashMap<char, usize> = HashMap::new();
|
||||||
// count the chars in each word
|
// count the chars in each word
|
||||||
|
@ -58,8 +58,8 @@ pub trait WordList: Clone + std::fmt::Debug + Default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// make all chars to strings
|
// convert to relative frequency
|
||||||
let cmap: HashMap<Word, usize> = cmap.into_iter().map(|p| (p.0.to_string(), p.1)).collect();
|
let n: f64 = cmap.keys().len() as f64;
|
||||||
WordMap::from_absolute(cmap)
|
cmap.into_iter().map(|p| (p.0, p.1 as f64 / n)).collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,3 +103,9 @@ impl From<HashMap<Word, Frequency>> for WordMap {
|
||||||
Self { inner: value }
|
Self { inner: value }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<WordMap > for HashMap<Word, Frequency>{
|
||||||
|
fn from(value: WordMap) -> Self {
|
||||||
|
value.inner
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue