pub fn part_1(inp: String) -> i32 {
    let input = parse_input(inp);
    let bit_length = input[0].chars().count();
    let total_length = input.len();
    let mut bit_sums: Vec<usize> = Vec::new();
    bit_sums.resize_with(bit_length, || 0);

    for l in input {
        let bits = l
            .chars()
            .map(|c| c.to_string().parse::<usize>().unwrap())
            .collect::<Vec<usize>>();

        for (i, b) in bits.iter().enumerate() {
            bit_sums[i] += b;
        }
    }

    let mut gamma = String::new();
    let mut epsilon = String::new();
    for b in bit_sums {
        if b > (total_length / 2) {
            gamma.push('1');
            epsilon.push('0');
        } else {
            gamma.push('0');
            epsilon.push('1');
        }
    }

    let gamma_rate = i32::from_str_radix(&gamma, 2).unwrap();
    let epsilon_rate = i32::from_str_radix(&epsilon, 2).unwrap();

    gamma_rate * epsilon_rate
}
// TODO: should try to solve this in the "binary domain"
// instead of in the "String domain"
should try to solve this in the "binary domain"
instead of in the "String domain"
should try to solve this in the " binary domain " instead of in the " String domain "
pub fn part_1(inp: String) -> i32 {
    let input = parse_input(inp);
    let bit_length = input[0].chars().count();
    let total_length = input.len();
    let mut bit_sums: Vec<usize> = Vec::new();
    bit_sums.resize_with(bit_length, || 0);
    for l in input {
        let bits = l
            .chars()
            .map(|c| c.to_string().parse::<usize>().unwrap())
            .collect::<Vec<usize>>();
        for (i, b) in bits.iter().enumerate() {
            bit_sums[i] += b;
        }
    }
    let mut gamma = String::new();
    let mut epsilon = String::new();
    for b in bit_sums {
        if b > (total_length / 2) {
            gamma.push('1');
            epsilon.push('0');
        } else {
            gamma.push('0');
            epsilon.push('1');
        }
    }
    let gamma_rate = i32::from_str_radix(&gamma, 2).unwrap();
    let epsilon_rate = i32::from_str_radix(&epsilon, 2).unwrap();
    gamma_rate * epsilon_rate
}
pub fn part_1 ( inp : String ) -> i32 { let input = parse_input ( inp ) ; let bit_length = input [ 0 ] . chars ( ) . count ( ) ; let total_length = input . len ( ) ; let mut bit_sums : Vec < usize > = Vec :: new ( ) ; bit_sums . resize_with ( bit_length , | | 0 ) ; for l in input { let bits = l . chars ( ) . map ( | c | c . to_string ( ) . parse :: < usize > ( ) . unwrap ( ) ) . collect :: < Vec < usize > > ( ) ; for ( i , b ) in bits . iter ( ) . enumerate ( ) { bit_sums [ i ] += b ; } } let mut gamma = String :: new ( ) ; let mut epsilon = String :: new ( ) ; for b in bit_sums { if b > ( total_length / 2 ) { gamma . push ( '1' ) ; epsilon . push ( '0' ) ; } else { gamma . push ( '0' ) ; epsilon . push ( '1' ) ; } } let gamma_rate = i32 :: from_str_radix ( & gamma , 2 ) . unwrap ( ) ; let epsilon_rate = i32 :: from_str_radix ( & epsilon , 2 ) . unwrap ( ) ; gamma_rate * epsilon_rate }
TODO: should try to solve this in the "binary domain"
instead of in the "String domain"
TODO : should try to solve this in the " binary domain " instead of in the " String domain "
inp
String