From aec57c8690d4efd8f294f3ecd96dc5c8afb723a8 Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Thu, 9 Dec 2021 02:11:30 -0500 Subject: [PATCH] Make input parsing more defensive --- day9/src/main.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/day9/src/main.rs b/day9/src/main.rs index 78f08e9..ccbc6ed 100644 --- a/day9/src/main.rs +++ b/day9/src/main.rs @@ -157,6 +157,12 @@ fn main() { }) .collect::>(); + let first_row_length = input_lines.get(0).expect("input must be non-empty").len(); + assert!( + input_lines.iter().all(|row| row.len() == first_row_length), + "All input lines must be the same length" + ); + println!("Part 1: {}", part1(&input_lines)); println!("Part 2: {}", part2(&input_lines)); }