From f86be23eca2107c5f7d775fd7e2818e80905c7d0 Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Wed, 24 Jan 2024 22:58:19 +0100 Subject: [PATCH] calculate sum of expanded values --- src/day09/mod.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/day09/mod.rs b/src/day09/mod.rs index 1ae6619..a6c6f9f 100644 --- a/src/day09/mod.rs +++ b/src/day09/mod.rs @@ -9,22 +9,24 @@ pub fn main() { let input = split_inputs(lines, &r"\s+"); let sequences = convert_num(input); - let structures: Vec>> = sequences + let predictions: Vec = sequences .iter() .map(|s| { let current = s.to_vec(); let mut next = extra_diff(current); expand(&mut next); - next + next.first() + .unwrap() + .last() + .unwrap() + .clone() }) .collect(); - - for seq in structures[0].clone() { - for n in seq { - print!("{n} "); - } - println!(""); - } + let sum: i32 = predictions + .iter() + .sum(); + + println!("The sum of all prediction values is: '{sum}'."); } fn expand(strct: &mut Vec>) {