From 97c5310ead38e0d213fd1478b39df91fd255bb50 Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Wed, 24 Jan 2024 23:16:45 +0100 Subject: [PATCH] isolate into part one function --- src/day09/mod.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/day09/mod.rs b/src/day09/mod.rs index a6c6f9f..73c3f9e 100644 --- a/src/day09/mod.rs +++ b/src/day09/mod.rs @@ -8,24 +8,35 @@ pub fn main() { let lines = split_lines(&content); let input = split_inputs(lines, &r"\s+"); - let sequences = convert_num(input); - let predictions: Vec = sequences + let sequences = convert_num(input); + let structures: Vec>> = sequences .iter() .map(|s| { let current = s.to_vec(); let mut next = extra_diff(current); expand(&mut next); - next.first() + next + }) + .collect(); + + part_one(&structures); +} + +fn part_one(strcts: &Vec>>) { + let predictions: Vec = strcts + .iter() + .map(|seq| + seq + .first() .unwrap() .last() .unwrap() .clone() - }) - .collect(); + ).collect(); let sum: i32 = predictions .iter() .sum(); - + println!("The sum of all prediction values is: '{sum}'."); }