From d54bddde27bf48ae044c055702e44eb917ecefd4 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Fri, 3 Dec 2021 16:15:50 +0100 Subject: [PATCH] 2021: day03: assert that input is safe --- aoc2021/src/day03.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/aoc2021/src/day03.rs b/aoc2021/src/day03.rs index 69989e5..fababff 100644 --- a/aoc2021/src/day03.rs +++ b/aoc2021/src/day03.rs @@ -64,8 +64,13 @@ fn compute_epsilon(gamma: u64, size: usize) -> u64 { fn part2(input: &str) -> Result { let binary_numbers: Vec<&str> = input.lines().collect(); + // all binary numbers should have the same length let size = binary_numbers[0].len(); + #[cfg(debug_assertions)] + binary_numbers.iter().for_each(|num| { + debug_assert_eq!(num.len(), size); + }); let oxygen_generator_rating = compute_oxygen_generator_rating(&binary_numbers, size)?; let co2_scrubber_rating = compute_co2_scrubber_rating(&binary_numbers, size)?;