Wasnt working with the original input file. Crashed with the new line.

This commit is contained in:
Pedro de Oliveira 2023-05-05 20:58:24 +01:00
parent 1a87d8c6b3
commit b90110ef0f
1 changed files with 13 additions and 8 deletions

View File

@ -20,15 +20,20 @@ struct Position {
pub fn parse_input(input: &str) -> Vec<Move> { pub fn parse_input(input: &str) -> Vec<Move> {
input input
.split(", ") .lines()
.map(|item| { .map(|line| {
let num = item[1..].parse::<u16>().unwrap(); line.split(", ")
match &item[0..1] { .map(|item| {
"L" => Move::Left(num), let num = item[1..].parse::<u16>().unwrap();
"R" => Move::Right(num), match &item[0..1] {
_ => panic!("invalid"), "L" => Move::Left(num),
} "R" => Move::Right(num),
_ => panic!("invalid"),
}
})
.collect::<Vec<Move>>()
}) })
.flatten()
.collect() .collect()
} }