diff --git a/src/main.rs b/src/main.rs index 0a225d6..3394735 100644 --- a/src/main.rs +++ b/src/main.rs @@ -126,7 +126,13 @@ impl Wordlist { fn make_weights(&self) -> Weightlist { let mut weights = Weightlist::new(); self.inner.iter().for_each(|w| { - w.origin.chars().for_each(|c| weights.addweight(c)); + let mut found = Vec::new(); + w.origin.chars().for_each(|c| { + if !found.contains(&c) { + weights.addweight(c); + found.push(c); + } + }); }); weights } @@ -159,7 +165,7 @@ impl Ord for TotalScore { fn cmp(&self, other: &Self) -> std::cmp::Ordering { match self.score.cmp(&other.score) { std::cmp::Ordering::Equal => { - if let (Some(w1), Some(w2)) = (self.words.first(), other.words.first()) { + if let (Some(w1), Some(w2)) = (self.words.last(), other.words.last()) { w1.cmp(w2) } else { std::cmp::Ordering::Equal @@ -185,6 +191,7 @@ fn backtrack_best( if depth == 0 { TotalScore::default() } else { + // println!("Starts new track: TS[{:?}]", &total_score); // Sort original data let mut list = origin_list.clone(); let weights = origin_weights.clone(); @@ -193,9 +200,9 @@ fn backtrack_best( // Pick n bests word, backtrack their score and return the best of the best results let mut list_guesses = Vec::new(); - for i in 0..10 { + for i in 0..15 { let guess = list.guess(i); - // println!("{:?}", guess); + // println!("Guess: {:?}", guess); let mut weights = origin_weights.clone(); weights.remove_word(&guess); // Backtrack the implied scores @@ -208,6 +215,7 @@ fn backtrack_best( }); } list_guesses.sort(); + // println!("List guesses {:#?}", list_guesses); let best_implied_score = list_guesses.last().unwrap().clone(); // println!("best impl: {:?}", best_implied_score); total_score.add(best_implied_score);