fn suggest(
    set: DictionarySet,
    word_list: WordList,
) -> Result<Vec<(&'static str, usize, i64)>, std::io::Error> {
    println!("Words remaining: {}", word_list.word_count());
    let mut words = word_list.get();
    words.par_sort_by_key(|word| pattern_from_word(*word));

    let grouped = words
        .iter()
        .group_by(|word| pattern_from_word(*word))
        .into_iter()
        .map(|(key, group)| (key, group.cloned().collect_vec()))
        .collect_vec();

    let mut reduction = grouped
        .par_iter()
        .flat_map(|(char_pattern, pattern_words)| {
            let mut hist: HashHistogram<u8> = HashHistogram::new();
            for word in words.iter() {
                let bucket = char_pattern.chars().fold(0_u8, |acc, c| {
                    (acc << 1) + if word.contains(c) { 1 } else { 0 }
                });
                hist.bump(&bucket);
            }

            let remaining = hist.iter().map(|(_, count)| *count).max().unwrap_or(0);
            pattern_words
                .into_iter()
                .map(move |w| (*w, remaining))
                .par_bridge()
        })
        .map(|(word, count)| (word, count, calculate_score(&set, word)))
        .collect::<Vec<(&'static str, usize, i64)>>();

    reduction.par_sort_by_key(|(word, count, score)| (*count, -*score, *word));
    Ok(reduction)
}
/// The algorithm here is to find out how well words bisect the problem space. For that we create a 5-bit
/// value for each word in the list determining with that letter is contained in the guess. For speed we
/// group words that have the same letters together (i.e. order of the letters is not important) and
/// rate the candidate words by the smallest max bucket (i.e. worst-case performance). Algorithm is O(o^2).
///
/// We also calculate a second value--position score--which indicates how many times a word has an
/// exact-position match. The higher the score the more likely it is a guess will cut the working set
/// dramatically.
The algorithm here is to find out how well words bisect the problem space. For that we create a 5-bit
value for each word in the list determining with that letter is contained in the guess. For speed we
group words that have the same letters together  and
rate the candidate words by the smallest max bucket .


The algorithm here is to find out how well words bisect the problem space . For that we create a 5 - bit value for each word in the list determining with that letter is contained in the guess . For speed we group words that have the same letters together and rate the candidate words by the smallest max bucket .
fn suggest(
    set: DictionarySet,
    word_list: WordList,
) -> Result<Vec<(&'static str, usize, i64)>, std::io::Error> {
    println!("Words remaining: {}", word_list.word_count());
    let mut words = word_list.get();
    words.par_sort_by_key(|word| pattern_from_word(*word));
    let grouped = words
        .iter()
        .group_by(|word| pattern_from_word(*word))
        .into_iter()
        .map(|(key, group)| (key, group.cloned().collect_vec()))
        .collect_vec();
    let mut reduction = grouped
        .par_iter()
        .flat_map(|(char_pattern, pattern_words)| {
            let mut hist: HashHistogram<u8> = HashHistogram::new();
            for word in words.iter() {
                let bucket = char_pattern.chars().fold(0_u8, |acc, c| {
                    (acc << 1) + if word.contains(c) { 1 } else { 0 }
                });
                hist.bump(&bucket);
            }
            let remaining = hist.iter().map(|(_, count)| *count).max().unwrap_or(0);
            pattern_words
                .into_iter()
                .map(move |w| (*w, remaining))
                .par_bridge()
        })
        .map(|(word, count)| (word, count, calculate_score(&set, word)))
        .collect::<Vec<(&'static str, usize, i64)>>();
    reduction.par_sort_by_key(|(word, count, score)| (*count, -*score, *word));
    Ok(reduction)
}
fn suggest ( set : DictionarySet , word_list : WordList , ) -> Result < Vec < ( & ' static str , usize , i64 ) > , std :: io :: Error > { println ! ( " " word_list word_count ( ) ) ; let mut words = word_list . get ( ) ; words . par_sort_by_key ( | word | pattern_from_word ( * word ) ) ; let grouped = words . iter ( ) . group_by ( | word | pattern_from_word ( * word ) ) . into_iter ( ) . map ( | ( key , group ) | ( key , group . cloned ( ) . collect_vec ( ) ) ) . collect_vec ( ) ; let mut reduction = grouped . par_iter ( ) . flat_map ( | ( char_pattern , pattern_words ) | { let mut hist : HashHistogram < u8 > = HashHistogram :: new ( ) ; for word in words . iter ( ) { let bucket = char_pattern . chars ( ) . fold ( 0_u8 , | acc , c | { ( acc << 1 ) + if word . contains ( c ) { 1 } else { 0 } } ) ; hist . bump ( & bucket ) ; } let remaining = hist . iter ( ) . map ( | ( _ , count ) | * count ) . max ( ) . unwrap_or ( 0 ) ; pattern_words . into_iter ( ) . map ( move | w | ( * w , remaining ) ) . par_bridge ( ) } ) . map ( | ( word , count ) | ( word , count , calculate_score ( & set , word ) ) ) . collect :: < Vec < ( & ' static str , usize , i64 ) > > ( ) ; reduction . par_sort_by_key ( | ( word , count , score ) | ( * count , - * score , * word ) ) ; Ok ( reduction ) }
The algorithm here is to find out how well words bisect the problem space.
The algorithm here is to find out how well words bisect the problem space .
set
DictionarySet
word_list
WordList