Function advent_of_code_2021::day_3::analyse_diagnostics[−][src]

fn analyse_diagnostics(data: &Vec<usize>, length: usize) -> (usize, usize)
Expand description

This solves part one, returning the pair of required values. It calculates the gamma value by iterating through each bit in the input strings and comparing the result of count_bit to the size of the data. The epsilon value is the bitwise inverse of that.

Example from puzzle specification

let test_data = vec![
    0b00100,
    0b11110,
    0b10110,
    0b10111,
    0b10101,
    0b01111,
    0b00111,
    0b11100,
    0b10000,
    0b11001,
    0b00010,
    0b01010,
];

assert_eq!(analyse_diagnostics(&test_data, 5), (22, 9));