From ea0ffa52294f7a3b1cee41bd51d530a14eb99773 Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Wed, 24 Jan 2024 23:38:32 +0100 Subject: [PATCH] better daily partition isolation --- src/day09/mod.rs | 43 ++++++++++++++++++++----------------------- src/main.rs | 2 +- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/day09/mod.rs b/src/day09/mod.rs index 73c3f9e..b65ec61 100644 --- a/src/day09/mod.rs +++ b/src/day09/mod.rs @@ -1,38 +1,25 @@ use crate::common::{convert_num, read_file, split_inputs, split_lines}; -pub fn main() { - let name = "day09"; - println!("Executing module '{name}' entrypoint . . . "); - - let content = read_file(name); - let lines = split_lines(&content); - let input = split_inputs(lines, &r"\s+"); +pub fn part_two() { + unimplemented!(); +} - let sequences = convert_num(input); - let structures: Vec>> = sequences +pub fn part_one() { + let sequences = setup(); + let predictions: Vec = sequences .iter() .map(|s| { let current = s.to_vec(); let mut next = extra_diff(current); expand(&mut next); - next - }) - .collect(); - - part_one(&structures); -} - -fn part_one(strcts: &Vec>>) { - let predictions: Vec = strcts - .iter() - .map(|seq| - seq - .first() + next.first() .unwrap() .last() .unwrap() .clone() - ).collect(); + }) + .collect(); + let sum: i32 = predictions .iter() .sum(); @@ -99,3 +86,13 @@ fn seq_diff(seq: Vec) -> Vec { diff } + +fn setup() -> Vec> { + let name = "day09"; + println!("Executing module '{name}' entrypoint . . . "); + + let content = read_file(name); + let lines = split_lines(&content); + let input = split_inputs(lines, &r"\s+"); + convert_num(input) +} diff --git a/src/main.rs b/src/main.rs index ba0b22d..ba85fa3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,5 +3,5 @@ mod day09; fn main() { println!("Executing main entrypoint . . . "); - day09::main(); + day09::part_one(); }