From b53fb73e0eaa57ced4418cac87b0571b65e1a507 Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Sun, 5 Jan 2020 11:46:02 +0100 Subject: [PATCH] Preparing for day 17 part 2 --- src/day17.rs | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/day17.rs b/src/day17.rs index 52d5988..8aae48a 100644 --- a/src/day17.rs +++ b/src/day17.rs @@ -31,7 +31,9 @@ pub struct RobotTrackingSystem { start_position: (i32, i32), start_dir: Direction, crossings: Vec<(i32, i32)>, + dir_commands: Vec, + commands_sequences: [Vec<(i32, i32)>; 3], // 3 sequences: A, B and C. } impl RobotTrackingSystem { @@ -43,6 +45,7 @@ impl RobotTrackingSystem { start_dir: Direction::Up, crossings: Vec::<(i32, i32)>::new(), dir_commands: Vec::::new(), + commands_sequences: [Vec::<(i32, i32)>::new(), Vec::<(i32, i32)>::new(), Vec::<(i32, i32)>::new()], } } @@ -136,13 +139,20 @@ impl RobotTrackingSystem { break; } } + + fn find_sequences(&mut self) { + if !self.commands_sequences[0].is_empty() { return; } + + + } } impl intcode::IO for RobotTrackingSystem { - // Read instructions + // Read instructions fn read(&mut self) -> i64 { self.build_board_from_output(); - 42 // TODO: part2. + self.find_sequences(); + 42 } // Send to the output channel. @@ -166,3 +176,22 @@ pub fn part2(code: &[i64]) { intcode::execute_op_code_with_custom_io(code, &mut rts); } + +#[cfg(test)] +mod tests { + use super::*; + use itertools::Itertools; + + #[test] + fn foo() { + let array = vec![1, 2, 3]; + let s: i32 = array.iter().sum(); + dbg!(s); + let mut combinations: Vec> = (3..=7).combinations_with_replacement(3).sorted_by(|v1, v2| { + let s1: i32 = v1.iter().sum(); + let s2: i32 = v2.iter().sum(); + s1.cmp(&s2) + }).collect(); + println!("{:?}", combinations); + } +} \ No newline at end of file -- 2.45.2