From b90110ef0f603cd75b386924f248205327833e6f Mon Sep 17 00:00:00 2001 From: Pedro de Oliveira Date: Fri, 5 May 2023 20:58:24 +0100 Subject: [PATCH] Wasnt working with the original input file. Crashed with the new line. --- day01/src/lib.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/day01/src/lib.rs b/day01/src/lib.rs index c9442d9..3ccd595 100644 --- a/day01/src/lib.rs +++ b/day01/src/lib.rs @@ -20,15 +20,20 @@ struct Position { pub fn parse_input(input: &str) -> Vec { input - .split(", ") - .map(|item| { - let num = item[1..].parse::().unwrap(); - match &item[0..1] { - "L" => Move::Left(num), - "R" => Move::Right(num), - _ => panic!("invalid"), - } + .lines() + .map(|line| { + line.split(", ") + .map(|item| { + let num = item[1..].parse::().unwrap(); + match &item[0..1] { + "L" => Move::Left(num), + "R" => Move::Right(num), + _ => panic!("invalid"), + } + }) + .collect::>() }) + .flatten() .collect() }