From cd14389fe93dc5afe4ea07ce1e84b4919b1d0dd9 Mon Sep 17 00:00:00 2001 From: Samuel Ortion Date: Sun, 10 Dec 2023 20:05:40 +0100 Subject: [PATCH] day5: Parse seeds --- days/05/rust/part1/Cargo.toml | 8 ++++++++ days/05/rust/part1/src/main.rs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 days/05/rust/part1/Cargo.toml create mode 100644 days/05/rust/part1/src/main.rs diff --git a/days/05/rust/part1/Cargo.toml b/days/05/rust/part1/Cargo.toml new file mode 100644 index 0000000..d53465e --- /dev/null +++ b/days/05/rust/part1/Cargo.toml @@ -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] diff --git a/days/05/rust/part1/src/main.rs b/days/05/rust/part1/src/main.rs new file mode 100644 index 0000000..ca6e4a5 --- /dev/null +++ b/days/05/rust/part1/src/main.rs @@ -0,0 +1,32 @@ +use std::fs; + +fn parse_steps(content: &str) -> Vec>> { + let mut steps: Vec>> = 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 = seeds + .iter() + .map(|string| { + let number: u32 = string.trim().parse().unwrap(); + number + }) + .collect(); + for seed in seeds { + println!("{:?}", seed); + } +}