isolate into part one function

This commit is contained in:
Baipyrus 2024-01-24 23:16:45 +01:00
parent f86be23eca
commit 97c5310ead

View File

@ -9,19 +9,30 @@ pub fn main() {
let input = split_inputs(lines, &r"\s+"); let input = split_inputs(lines, &r"\s+");
let sequences = convert_num(input); let sequences = convert_num(input);
let predictions: Vec<i32> = sequences let structures: Vec<Vec<Vec<i32>>> = sequences
.iter() .iter()
.map(|s| { .map(|s| {
let current = s.to_vec(); let current = s.to_vec();
let mut next = extra_diff(current); let mut next = extra_diff(current);
expand(&mut next); expand(&mut next);
next.first() next
})
.collect();
part_one(&structures);
}
fn part_one(strcts: &Vec<Vec<Vec<i32>>>) {
let predictions: Vec<i32> = strcts
.iter()
.map(|seq|
seq
.first()
.unwrap() .unwrap()
.last() .last()
.unwrap() .unwrap()
.clone() .clone()
}) ).collect();
.collect();
let sum: i32 = predictions let sum: i32 = predictions
.iter() .iter()
.sum(); .sum();