2MPN73UJBT4AA44CVFCBRLB4BRO44BNASUXTFF3NZIEFN7EGENWQC
// Despite what a human might think these words contain different letters, the input uses Greek
// A and B while the list of potential anagrams uses Latin A and B.
let word = "ΑΒΓ";
// Despite what a human might think these words contain different letters, the input uses Greek
// A and B while the list of potential anagrams uses Latin A and B.
let word = "ΑΒΓ";
pub fn anagrams_for<'a>(word: &str, possible_anagrams: &[&str]) -> HashSet<&'a str> {
unimplemented!(
"For the '{}' word find anagrams among the following words: {:?}",
word,
possible_anagrams
);
fn grapheme_histogram(word: &str) -> HashMap<&str, usize> {
word.graphemes(true).fold(
HashMap::with_capacity(word.len()),
|mut hashmap, grapheme| {
*hashmap.entry(grapheme).or_insert(0) += 1;
hashmap
},
)
pub fn anagrams_for<'a>(word: &str, possible_anagrams: &[&'a str]) -> HashSet<&'a str> {
let word_lowercased = word.to_lowercase();
let (word_checksum, word_histogram) = (
checksum(&word_lowercased),
grapheme_histogram(&word_lowercased),
);
possible_anagrams
.iter()
.filter(|possible_anagram| {
word.len() == possible_anagram.len() && {
let possible_anagram = possible_anagram.to_lowercase();
word_lowercased != possible_anagram
&& word_checksum == checksum(&possible_anagram)
&& word_histogram == grapheme_histogram(&possible_anagram)
}
})
.copied()
.collect()
}
[dependencies]
unicode-segmentation = "1.8"