Skip to content

Instantly share code, notes, and snippets.

@popey456963
Last active January 14, 2022 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save popey456963/a654e98d0180566b897b70ee54c400e2 to your computer and use it in GitHub Desktop.
Save popey456963/a654e98d0180566b897b70ee54c400e2 to your computer and use it in GitHub Desktop.
Wordle best clue calculator
fn best_clue(words_list: &Vec<Vec<char>>) -> Clue {
words_list
.par_iter()
.enumerate()
.map(|(i, word)| {
let mut bucket_counts = [0; 3_usize.pow(5)];
for j in 0..words_list.len() {
//let overlap = fast_calculate_word_overlap(&word_overlaps, word_count, i, j);
let overlap = calculate_word_overlap(&word, &words_list[j]);
bucket_counts[overlap_to_index(&overlap)] += 1;
}
let value = match &SCORE_METHOD {
ScoreType::MinimiseLargestBucketSize => *bucket_counts.iter().max().unwrap(),
ScoreType::MinimiseVariance => {
let average = bucket_counts.iter().sum::<usize>() / bucket_counts.len();
bucket_counts
.iter()
.map(|v| (v - average).pow(2))
.sum::<usize>()
}
};
Clue {
value: value,
word: word.to_vec(),
}
})
.min_by(|a, b| a.value.cmp(&b.value))
.unwrap()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment