day5: Parse maps
This commit is contained in:
parent
cd14389fe9
commit
ff5656b694
|
@ -1,7 +1,25 @@
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
fn parse_steps(content: &str) -> Vec<Vec<Vec<u32>>> {
|
fn parse_steps(lines: std::str::Lines) -> Vec<Vec<Vec<u32>>> {
|
||||||
let mut steps: Vec<Vec<Vec<u32>>> = Vec::new();
|
let mut steps: Vec<Vec<Vec<u32>>> = Vec::new();
|
||||||
|
let mut step: Vec<Vec<u32>> = 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<u32> = numbers
|
||||||
|
.iter()
|
||||||
|
.map(|string| {
|
||||||
|
let number: u32 = string.parse().unwrap();
|
||||||
|
number
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
let n = steps.len();
|
||||||
|
steps[n - 1].push(numbers);
|
||||||
|
}
|
||||||
|
}
|
||||||
steps
|
steps
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +37,10 @@ fn main() {
|
||||||
.expect("Should have a seed")
|
.expect("Should have a seed")
|
||||||
.split(" ")
|
.split(" ")
|
||||||
.collect();
|
.collect();
|
||||||
|
let steps = parse_steps(lines);
|
||||||
|
for step in steps {
|
||||||
|
println!("{:?}", step);
|
||||||
|
}
|
||||||
let seeds: Vec<u32> = seeds
|
let seeds: Vec<u32> = seeds
|
||||||
.iter()
|
.iter()
|
||||||
.map(|string| {
|
.map(|string| {
|
||||||
|
|
Loading…
Reference in New Issue