fn count(rows: &Vec<&str>) -> (Vec<usize>, Vec<usize>) {
    let word_length = rows[0].len();

    // Calculate counts of 0s/1s in bit positions
    let mut zero_counts = vec![0; word_length];
    let mut one_counts = vec![0; word_length];
    for row in rows {
        // println!("row: {:?}", row);
        let mut frequency: HashMap<char, i32> = HashMap::new();
        let columns: Vec<char> = row.chars().collect();
        // println!("{:?}", columns);
        for (idx, column) in columns.iter().enumerate() {
            let key = row.chars().nth(idx).unwrap();
            // print_type_of(&key);
            *frequency.entry(key).or_insert(0) += 1;
            if column == &'0' {
                zero_counts[idx] += 1;
            } else {
                one_counts[idx] += 1;
            }
        }
    }
    return (zero_counts, one_counts);
}
// Frequency count of 0s and 1s
Frequency count of 0s and 1s
Frequency count of 0s and 1s
fn count(rows: &Vec<&str>) -> (Vec<usize>, Vec<usize>) {
    let word_length = rows[0].len();
    // Calculate counts of 0s/1s in bit positions
    let mut zero_counts = vec![0; word_length];
    let mut one_counts = vec![0; word_length];
    for row in rows {
        // println!("row: {:?}", row);
        let mut frequency: HashMap<char, i32> = HashMap::new();
        let columns: Vec<char> = row.chars().collect();
        // println!("{:?}", columns);
        for (idx, column) in columns.iter().enumerate() {
            let key = row.chars().nth(idx).unwrap();
            // print_type_of(&key);
            *frequency.entry(key).or_insert(0) += 1;
            if column == &'0' {
                zero_counts[idx] += 1;
            } else {
                one_counts[idx] += 1;
            }
        }
    }
    return (zero_counts, one_counts);
}
fn count ( rows : & Vec < & str > ) -> ( Vec < usize > , Vec < usize > ) { let word_length = rows [ 0 ] . len ( ) ; // Calculate counts of 0s/1s in bit positions let mut zero_counts = vec ! [ 0 word_length ] ; let mut one_counts = vec ! [ 0 word_length ] ; for row in rows { // println!("row: {:?}", row); let mut frequency : HashMap < char , i32 > = HashMap :: new ( ) ; let columns : Vec < char > = row . chars ( ) . collect ( ) ; // println!("{:?}", columns); for ( idx , column ) in columns . iter ( ) . enumerate ( ) { let key = row . chars ( ) . nth ( idx ) . unwrap ( ) ; // print_type_of(&key); * frequency . entry ( key ) . or_insert ( 0 ) += 1 ; if column == & '0' { zero_counts [ idx ] += 1 ; } else { one_counts [ idx ] += 1 ; } } } return ( zero_counts , one_counts ) ; }
Frequency count of 0s and 1s
Frequency count of 0s and 1s
rows
&Vec<&str>
rows
&Vec<&str>