From 30695d92ddd8329ee2b7c1f498a8c73685f4d175 Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Wed, 24 Jan 2024 22:57:50 +0100 Subject: [PATCH] expand sequences --- src/day09/mod.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/day09/mod.rs b/src/day09/mod.rs index 3f11394..1ae6619 100644 --- a/src/day09/mod.rs +++ b/src/day09/mod.rs @@ -11,7 +11,12 @@ pub fn main() { let sequences = convert_num(input); let structures: Vec>> = sequences .iter() - .map(|s| extra_diff(s.to_vec())) + .map(|s| { + let current = s.to_vec(); + let mut next = extra_diff(current); + expand(&mut next); + next + }) .collect(); for seq in structures[0].clone() { @@ -30,6 +35,29 @@ fn expand(strct: &mut Vec>) { .last() .unwrap() ); + + for i in (0..strct.len() - 1).rev() { + let last = strct + .get(i + 1) + .unwrap() + .clone(); + let current = strct + .get_mut(i) + .unwrap(); + + + let next = + current + .last() + .unwrap() + .clone() + + last + .last() + .unwrap() + .clone(); + + current.push(next); + } } fn extra_diff(seq: Vec) -> Vec> {