From 8ad6df2ab6652a4fee781f33ff158e86771bee41 Mon Sep 17 00:00:00 2001 From: Tobias Berger Date: Fri, 2 Dec 2022 15:25:16 +0100 Subject: [PATCH] Rust Day 2 - Handle crlf line endings --- rust/src/day02/main.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/rust/src/day02/main.rs b/rust/src/day02/main.rs index 93eb457..2c22bb8 100644 --- a/rust/src/day02/main.rs +++ b/rust/src/day02/main.rs @@ -125,11 +125,12 @@ impl FromStr for GameResult { fn parse_input_part_1() -> Vec<[Shape; 2]> { INPUT - .split('\n') + .lines() .map(|round_string| { let round = round_string .split(' ') .map(|play| { + assert_eq!(play.len(), 1, "play: {play}"); Shape::from_str(play).unwrap_or_else(|_| panic!("Found invalid play {play}")) }) .take(2) @@ -141,10 +142,12 @@ fn parse_input_part_1() -> Vec<[Shape; 2]> { fn parse_input_part_2() -> Vec<(Shape, GameResult)> { INPUT - .split('\n') + .lines() .map(|round_string| { let round = round_string.split(' ').take(2).collect::>(); assert_eq!(round.len(), 2); + assert_eq!(round[0].len(), 1); + assert_eq!(round[1].len(), 1); let enemy_shape = Shape::from_str(round[0]) .unwrap_or_else(|_| panic!("Found invalid play {}", round[0])); let desired_result = GameResult::from_str(round[1])