diff --git a/src/main.rs b/src/main.rs index 4db0501..2584425 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,7 +26,7 @@ fn main() { println!("{len}: {}", path.into_iter().collect::>().join(" ")); } -const MAX_SOLUTION_LENGTH: u8 = 50; +const MAX_SOLUTION_LENGTH: u8 = 200; fn solve(dictionary: &mut [(String, LetterSet)], target: LetterSet) -> (u8, HashSet) { let mut bests = (0..=LetterSet::FULL.to_index()) @@ -35,6 +35,9 @@ fn solve(dictionary: &mut [(String, LetterSet)], target: LetterSet) -> (u8, Hash println!("allocated!"); bests[LetterSet::FULL.to_index()] = (0, HashSet::new()); + dictionary.sort_by_key(|(word, ls)| word.len() - usize::from(ls.len())); + println!("sorted!"); + score(dictionary, &mut bests, target.negation(), 0); bests[target.negation().to_index()].clone() @@ -62,13 +65,17 @@ fn score( let Some((word, ls, score)) = dictionary .iter() - .filter(|(_, ls)| !ls.difference(done_letters).is_empty()) + .filter(|(word, ls)| { + (!ls.difference(done_letters).is_empty()) + && u8::try_from(word.len()).unwrap().saturating_add(length) <= MAX_SOLUTION_LENGTH + }) .map(|(word, ls)| { let word_len = u8::try_from(word.len()).unwrap(); let new_length = word_len.saturating_add(length); let rest_score = score(dictionary, bests, done_letters.union(*ls), new_length); (word, ls, word_len.saturating_add(rest_score)) }) + .take(2000) .min_by_key(|(_, _, score)| *score) else { return u8::MAX;