crazy crazy memory usage
32: BEG ACQUIT ANKH AMPLY FAX JAW ARVOS ADZ
This commit is contained in:
parent
7cbaf40d44
commit
ed49037643
1 changed files with 9 additions and 2 deletions
11
src/main.rs
11
src/main.rs
|
|
@ -26,7 +26,7 @@ fn main() {
|
||||||
println!("{len}: {}", path.into_iter().collect::<Vec<_>>().join(" "));
|
println!("{len}: {}", path.into_iter().collect::<Vec<_>>().join(" "));
|
||||||
}
|
}
|
||||||
|
|
||||||
const MAX_SOLUTION_LENGTH: u8 = 50;
|
const MAX_SOLUTION_LENGTH: u8 = 200;
|
||||||
|
|
||||||
fn solve(dictionary: &mut [(String, LetterSet)], target: LetterSet) -> (u8, HashSet<String>) {
|
fn solve(dictionary: &mut [(String, LetterSet)], target: LetterSet) -> (u8, HashSet<String>) {
|
||||||
let mut bests = (0..=LetterSet::FULL.to_index())
|
let mut bests = (0..=LetterSet::FULL.to_index())
|
||||||
|
|
@ -35,6 +35,9 @@ fn solve(dictionary: &mut [(String, LetterSet)], target: LetterSet) -> (u8, Hash
|
||||||
println!("allocated!");
|
println!("allocated!");
|
||||||
bests[LetterSet::FULL.to_index()] = (0, HashSet::new());
|
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);
|
score(dictionary, &mut bests, target.negation(), 0);
|
||||||
|
|
||||||
bests[target.negation().to_index()].clone()
|
bests[target.negation().to_index()].clone()
|
||||||
|
|
@ -62,13 +65,17 @@ fn score(
|
||||||
|
|
||||||
let Some((word, ls, score)) = dictionary
|
let Some((word, ls, score)) = dictionary
|
||||||
.iter()
|
.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)| {
|
.map(|(word, ls)| {
|
||||||
let word_len = u8::try_from(word.len()).unwrap();
|
let word_len = u8::try_from(word.len()).unwrap();
|
||||||
let new_length = word_len.saturating_add(length);
|
let new_length = word_len.saturating_add(length);
|
||||||
let rest_score = score(dictionary, bests, done_letters.union(*ls), new_length);
|
let rest_score = score(dictionary, bests, done_letters.union(*ls), new_length);
|
||||||
(word, ls, word_len.saturating_add(rest_score))
|
(word, ls, word_len.saturating_add(rest_score))
|
||||||
})
|
})
|
||||||
|
.take(2000)
|
||||||
.min_by_key(|(_, _, score)| *score)
|
.min_by_key(|(_, _, score)| *score)
|
||||||
else {
|
else {
|
||||||
return u8::MAX;
|
return u8::MAX;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue