diff --git a/days/05/rust/part1/src/main.rs b/days/05/rust/part1/src/main.rs index ca6e4a5..30eaaa4 100644 --- a/days/05/rust/part1/src/main.rs +++ b/days/05/rust/part1/src/main.rs @@ -1,7 +1,25 @@ use std::fs; -fn parse_steps(content: &str) -> Vec>> { +fn parse_steps(lines: std::str::Lines) -> Vec>> { let mut steps: Vec>> = Vec::new(); + let mut step: Vec> = Vec::new(); + for line in lines { + if line.contains("-to-") { + step = Vec::new(); + steps.push(step); + } else if line != "" { + let numbers: Vec<&str> = line.split(" ").collect(); + let numbers: Vec = numbers + .iter() + .map(|string| { + let number: u32 = string.parse().unwrap(); + number + }) + .collect(); + let n = steps.len(); + steps[n - 1].push(numbers); + } + } steps } @@ -19,6 +37,10 @@ fn main() { .expect("Should have a seed") .split(" ") .collect(); + let steps = parse_steps(lines); + for step in steps { + println!("{:?}", step); + } let seeds: Vec = seeds .iter() .map(|string| {