day5: Parse seeds
This commit is contained in:
parent
9646029fea
commit
cd14389fe9
|
@ -0,0 +1,8 @@
|
||||||
|
[package]
|
||||||
|
name = "part1"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
|
@ -0,0 +1,32 @@
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
|
fn parse_steps(content: &str) -> Vec<Vec<Vec<u32>>> {
|
||||||
|
let mut steps: Vec<Vec<Vec<u32>>> = Vec::new();
|
||||||
|
steps
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let filepath: &str = "../../data/sample.txt";
|
||||||
|
|
||||||
|
let contents = fs::read_to_string(filepath).expect("Should have been hable to read the file");
|
||||||
|
|
||||||
|
let mut lines = contents.lines();
|
||||||
|
let seeds: Vec<&str> = lines
|
||||||
|
.next()
|
||||||
|
.unwrap()
|
||||||
|
.split(": ")
|
||||||
|
.nth(1)
|
||||||
|
.expect("Should have a seed")
|
||||||
|
.split(" ")
|
||||||
|
.collect();
|
||||||
|
let seeds: Vec<u32> = seeds
|
||||||
|
.iter()
|
||||||
|
.map(|string| {
|
||||||
|
let number: u32 = string.trim().parse().unwrap();
|
||||||
|
number
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
for seed in seeds {
|
||||||
|
println!("{:?}", seed);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue