converting inputs into numbers

This commit is contained in:
Baipyrus 2024-01-24 15:00:08 +01:00
parent 2abb8a6d49
commit 30f9c1bf88
2 changed files with 22 additions and 4 deletions

View File

@ -30,3 +30,18 @@ pub fn split_inputs(input: Vec<String>, re: &str) -> Vec<Vec<String>> {
result result
} }
pub fn convert_num(input: Vec<Vec<String>>) -> Vec<Vec<i32>> {
input
.into_iter()
.map(|a| {
a
.into_iter()
.map(|b| {
b
.trim()
.parse::<i32>()
.expect("Invalid numeric value in input!")
}).collect()
}).collect()
}

View File

@ -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() { pub fn main() {
let name = "day09"; let name = "day09";
@ -7,8 +7,11 @@ pub fn main() {
let content = read_file(name); let content = read_file(name);
let lines = split_lines(&content); let lines = split_lines(&content);
let input = split_inputs(lines, &r"\s+"); let input = split_inputs(lines, &r"\s+");
let sequences = convert_num(input);
for value in &input[0] { let sum_input_0: i32 = sequences[0]
print!("{value}, "); .clone()
} .into_iter()
.sum();
println!("Erste Summe: {sum_input_0}");
} }