fn checksum(&self) -> String {
            // compute the frequency for each letter characters in our encrypted_name.
            let mut char_to_freq = HashMap::new();
            for ch in self.0.chars().filter(|&ch| is_ascii_lower(ch)) {
                *char_to_freq.entry(ch).or_insert(0) += 1;
            }
            // build a vector of tuple (char, frequency) from the hash (key, value) so we can sort
            // our results.
            let mut vec: Vec<_> = char_to_freq.into_iter().collect();
            vec.sort_by(|&(cha, freqa), &(chb, freqb)| {
                // compare by the frequency (value) in the descending order (i.e. the most frequent
                // first), hence "b cmp a".
                match freqb.cmp(&freqa) {
                    // if a and b have the same frequency: "fallback" to the alphabetic
                    // (ascending) order, hence "a cmp b" this time.
                    ::std::cmp::Ordering::Equal => cha.cmp(&chb),
                    less_or_greater             => less_or_greater,
                }
            });

            vec.into_iter()
                .map(|(ch, _)| ch) // map to the char, we don't need the frequency anymore
                .take(5) // the checksum is *the five* most common letters
                .collect()
        }
/// Compute the checksum according to the puzzle definition.
///
/// > [...] the checksum is the five most common letters in the encrypted name, in order,
/// > with ties broken by alphabetization.
Compute the checksum according to the puzzle definition.
> [...] the checksum is the five most common letters in the encrypted name, in order,
> with ties broken by alphabetization.
Compute the checksum according to the puzzle definition . > [ ... ] the checksum is the five most common letters in the encrypted name in order > with ties broken by alphabetization .
fn checksum(&self) -> String {
            // compute the frequency for each letter characters in our encrypted_name.
            let mut char_to_freq = HashMap::new();
            for ch in self.0.chars().filter(|&ch| is_ascii_lower(ch)) {
                *char_to_freq.entry(ch).or_insert(0) += 1;
            }
            // build a vector of tuple (char, frequency) from the hash (key, value) so we can sort
            // our results.
            let mut vec: Vec<_> = char_to_freq.into_iter().collect();
            vec.sort_by(|&(cha, freqa), &(chb, freqb)| {
                // compare by the frequency (value) in the descending order (i.e. the most frequent
                // first), hence "b cmp a".
                match freqb.cmp(&freqa) {
                    // if a and b have the same frequency: "fallback" to the alphabetic
                    // (ascending) order, hence "a cmp b" this time.
                    ::std::cmp::Ordering::Equal => cha.cmp(&chb),
                    less_or_greater             => less_or_greater,
                }
            });
            vec.into_iter()
                .map(|(ch, _)| ch) // map to the char, we don't need the frequency anymore
                .take(5) // the checksum is *the five* most common letters
                .collect()
        }
fn checksum ( & self ) -> String { // compute the frequency for each letter characters in our encrypted_name. let mut char_to_freq = HashMap :: new ( ) ; for ch in self . 0 . chars ( ) . filter ( | & ch | is_ascii_lower ( ch ) ) { * char_to_freq . entry ( ch ) . or_insert ( 0 ) += 1 ; } // build a vector of tuple (char, frequency) from the hash (key, value) so we can sort // our results. let mut vec : Vec < _ > = char_to_freq . into_iter ( ) . collect ( ) ; vec . sort_by ( | & ( cha , freqa ) , & ( chb , freqb ) | { // compare by the frequency (value) in the descending order (i.e. the most frequent // first), hence "b cmp a". match freqb . cmp ( & freqa ) { // if a and b have the same frequency: "fallback" to the alphabetic // (ascending) order, hence "a cmp b" this time. :: std :: cmp :: Ordering :: Equal => cha . cmp ( & chb ) , less_or_greater => less_or_greater , } } ) ; vec . into_iter ( ) . map ( | ( ch , _ ) | ch ) // map to the char, we don't need the frequency anymore . take ( 5 ) // the checksum is *the five* most common letters . collect ( ) }
Compute the checksum according to the puzzle definition.
Compute the checksum according to the puzzle definition .
&self
&self