Function advent_of_code_2021::day_3::count_bit [−][src]
Expand description
Return the number of values in the data where all the bits set in the bitmask are also set in
the value. Utility function used by analyse_diagnostics. For this puzzle, only one bit is
set in the mask at a time.
Example from puzzle specification
let test_data = vec![
0b00100,
0b11110,
0b10110,
0b10111,
0b10101,
0b01111,
0b00111,
0b11100,
0b10000,
0b11001,
0b00010,
0b01010,
];
assert_eq!(count_bit(&test_data, 1 << 0), 5);
assert_eq!(count_bit(&test_data, 1 << 1), 7);
assert_eq!(count_bit(&test_data, 1 << 2), 8);
assert_eq!(count_bit(&test_data, 1 << 3), 5);
assert_eq!(count_bit(&test_data, 1 << 4), 7);