// Generalized function for calculting metrics in P2.
// Takes a function to select the digit to keep during filtering.
Generalized function for calculting metrics in P2.
Takes a function to select the digit to keep during filtering.
Generalized function for calculting metrics in P2 . Takes a function to select the digit to keep during filtering .
fn filter_binaries<F>(diagnostics: Vec<Vec<u8>>, digit_selection_fn: F) -> u32
where
    F: Fn(Vec<Vec<u8>>, usize) -> u8,
{
    let row_length = diagnostics[0].len();
    let remaining_binary_list = (0..row_length).fold(diagnostics, |acc, column| {
        // If length is 1, return acc for the remaining of the iteration (kind of equivalent to stopping :-)
        // Otherwise, the list will be emptied
        if acc.len() == 1 {
            return acc;
        }
        let selected_digit = digit_selection_fn(acc.clone(), column);
        acc.into_iter()
            .filter(|row| row[column] == selected_digit)
            .collect()
    });
    match &remaining_binary_list[..] {
        [remaining_binary] => {
            let with_bools = remaining_binary.iter().map(|&x| x == 1).collect();
            bitvec_to_u32(with_bools)
        }
        _ => panic!("Unexpected remaining binary count, expected exactly one binary"),
    }
}
fn filter_binaries < F > ( diagnostics : Vec < Vec < u8 > > , digit_selection_fn : F ) -> u32 where F : Fn ( Vec < Vec < u8 > > , usize ) -> u8 , { let row_length = diagnostics [ 0 ] . len ( ) ; let remaining_binary_list = ( 0 .. row_length ) . fold ( diagnostics , | acc , column | { // If length is 1, return acc for the remaining of the iteration (kind of equivalent to stopping :-) // Otherwise, the list will be emptied if acc . len ( ) == 1 { return acc ; } let selected_digit = digit_selection_fn ( acc . clone ( ) , column ) ; acc . into_iter ( ) . filter ( | row | row [ column ] == selected_digit ) . collect ( ) } ) ; match & remaining_binary_list [ .. ] { [ remaining_binary ] => { let with_bools = remaining_binary . iter ( ) . map ( | & x | x == 1 ) . collect ( ) ; bitvec_to_u32 ( with_bools ) } _ => panic ! ( " " ) , } }
Generalized function for calculting metrics in P2.
Generalized function for calculting metrics in P2 .
diagnostics
Vec<Vec<u8>>
digit_selection_fn
F