diff --git a/src/common/vectorize.rs b/src/common/vectorize.rs index 210ecbd..ca7177a 100644 --- a/src/common/vectorize.rs +++ b/src/common/vectorize.rs @@ -30,3 +30,18 @@ pub fn split_inputs(input: Vec, re: &str) -> Vec> { result } + +pub fn convert_num(input: Vec>) -> Vec> { + input + .into_iter() + .map(|a| { + a + .into_iter() + .map(|b| { + b + .trim() + .parse::() + .expect("Invalid numeric value in input!") + }).collect() + }).collect() +} diff --git a/src/day09/mod.rs b/src/day09/mod.rs index eed78a7..ef4c54c 100644 --- a/src/day09/mod.rs +++ b/src/day09/mod.rs @@ -1,4 +1,4 @@ -use crate::common::{read_file, split_inputs, split_lines}; +use crate::common::{convert_num, read_file, split_inputs, split_lines}; pub fn main() { let name = "day09"; @@ -7,8 +7,11 @@ pub fn main() { let content = read_file(name); let lines = split_lines(&content); let input = split_inputs(lines, &r"\s+"); + let sequences = convert_num(input); - for value in &input[0] { - print!("{value}, "); - } + let sum_input_0: i32 = sequences[0] + .clone() + .into_iter() + .sum(); + println!("Erste Summe: {sum_input_0}"); }