diff --git a/input/2023/day_11/input_test.txt b/input/2023/day_11/input_test.txt new file mode 100644 index 0000000..a0bda53 --- /dev/null +++ b/input/2023/day_11/input_test.txt @@ -0,0 +1,10 @@ +...#...... +.......#.. +#......... +.......... +......#... +.#........ +.........# +.......... +.......#.. +#...#..... \ No newline at end of file diff --git a/src/year_2023/day_11_cosmic_expantion/mod.rs b/src/year_2023/day_11_cosmic_expantion/mod.rs new file mode 100644 index 0000000..744b964 --- /dev/null +++ b/src/year_2023/day_11_cosmic_expantion/mod.rs @@ -0,0 +1,25 @@ +pub mod part_one; +//pub mod part_two; +//pub mod common; + +use crate::utils::solution::Solution; +use crate::utils::input_reader; + +pub struct DaySolution ; + + +impl Solution for DaySolution { + + fn input_path(&self) -> &'static str { + "input/2023/day_11/input_test.txt" + } + + fn part_one(&self) -> String { + input_reader::read_input_file(self.input_path(), part_one::part_one) + } + + fn part_two(&self) -> String { + //input_reader::read_input_file(self.input_path, part_two::part_two) + String::from("Not implemented") + } +} \ No newline at end of file diff --git a/src/year_2023/day_11_cosmic_expantion/part_one.rs b/src/year_2023/day_11_cosmic_expantion/part_one.rs new file mode 100644 index 0000000..4a535c7 --- /dev/null +++ b/src/year_2023/day_11_cosmic_expantion/part_one.rs @@ -0,0 +1,51 @@ +pub fn part_one(input_lines: Vec) -> String { + let vert_dim = input_lines.len(); + let horz_dim = input_lines[0].len(); + + let mut matrix = vec![vec![false; horz_dim]; vert_dim]; + + for (y, line) in input_lines.iter().enumerate() { + for (x, c) in line.chars().enumerate() { + matrix[x][y] = c == '#'; + } + } + + println!("Pre-expand dims: {:?}, {:?}", matrix.len(), matrix[0].len()); + + expand_rows(&mut matrix); + expand_cols(&mut matrix); + + println!("Post-expand dims: {:?}, {:?}", matrix.len(), matrix[0].len()); + + String::from("Not implemented") +} + +fn expand_rows(matrix: &mut Vec>) { + let mut i = 0; + while i < matrix.len() { + let row = matrix[i].clone(); + if all_false(&row) { + matrix.insert(i, row.clone()); + i += 1; + } + i += 1; + } +} + +fn expand_cols(matrix: &mut Vec>) { + let mut i = 0; + while i < matrix[0].len() { + let col = matrix.iter().map(|row| row[i]).collect::>(); + if all_false(&col) { + for row in matrix.iter_mut() { + row.insert(i, false); + } + i += 1; + } + i += 1; + } +} + +fn all_false(vector: &Vec) -> bool { + vector.iter().all(|x| *x == false) +} \ No newline at end of file diff --git a/src/year_2023/mod.rs b/src/year_2023/mod.rs index 7cfc9b1..9a7cd43 100644 --- a/src/year_2023/mod.rs +++ b/src/year_2023/mod.rs @@ -8,6 +8,7 @@ pub mod day_06_wait_for_it; pub mod day_08_haunted_wasteland; pub mod day_09_mirage_maintenance; pub mod day_10_pipe_maze; +pub mod day_11_cosmic_expantion; pub fn run(day: &str) { let solution: Box = match day { @@ -19,6 +20,7 @@ pub fn run(day: &str) { "8" => Box::new(day_08_haunted_wasteland::DaySolution), "9" => Box::new(day_09_mirage_maintenance::DaySolution), "10" => Box::new(day_10_pipe_maze::DaySolution), + "11" => Box::new(day_11_cosmic_expantion::DaySolution), _ => panic!("Invalid day specified"), };