day5: Parse seeds

This commit is contained in:
Samuel Ortion 2023-12-10 20:05:40 +01:00
parent 9646029fea
commit cd14389fe9
2 changed files with 40 additions and 0 deletions

View File

@ -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]

View File

@ -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);
}
}