mirror of
https://github.com/Baipyrus/AoC-23.git
synced 2024-11-14 17:53:49 +00:00
converting inputs into numbers
This commit is contained in:
parent
2abb8a6d49
commit
30f9c1bf88
@ -30,3 +30,18 @@ pub fn split_inputs(input: Vec<String>, re: &str) -> Vec<Vec<String>> {
|
||||
|
||||
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()
|
||||
}
|
||||
|
@ -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}");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user