2023-11: Start working on part one
This commit is contained in:
parent
20737cb432
commit
e0d5d12847
|
@ -0,0 +1,10 @@
|
||||||
|
...#......
|
||||||
|
.......#..
|
||||||
|
#.........
|
||||||
|
..........
|
||||||
|
......#...
|
||||||
|
.#........
|
||||||
|
.........#
|
||||||
|
..........
|
||||||
|
.......#..
|
||||||
|
#...#.....
|
|
@ -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")
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
pub fn part_one(input_lines: Vec<String>) -> 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<Vec<bool>>) {
|
||||||
|
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<Vec<bool>>) {
|
||||||
|
let mut i = 0;
|
||||||
|
while i < matrix[0].len() {
|
||||||
|
let col = matrix.iter().map(|row| row[i]).collect::<Vec<bool>>();
|
||||||
|
if all_false(&col) {
|
||||||
|
for row in matrix.iter_mut() {
|
||||||
|
row.insert(i, false);
|
||||||
|
}
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn all_false(vector: &Vec<bool>) -> bool {
|
||||||
|
vector.iter().all(|x| *x == false)
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ pub mod day_06_wait_for_it;
|
||||||
pub mod day_08_haunted_wasteland;
|
pub mod day_08_haunted_wasteland;
|
||||||
pub mod day_09_mirage_maintenance;
|
pub mod day_09_mirage_maintenance;
|
||||||
pub mod day_10_pipe_maze;
|
pub mod day_10_pipe_maze;
|
||||||
|
pub mod day_11_cosmic_expantion;
|
||||||
|
|
||||||
pub fn run(day: &str) {
|
pub fn run(day: &str) {
|
||||||
let solution: Box<dyn Solution> = match day {
|
let solution: Box<dyn Solution> = match day {
|
||||||
|
@ -19,6 +20,7 @@ pub fn run(day: &str) {
|
||||||
"8" => Box::new(day_08_haunted_wasteland::DaySolution),
|
"8" => Box::new(day_08_haunted_wasteland::DaySolution),
|
||||||
"9" => Box::new(day_09_mirage_maintenance::DaySolution),
|
"9" => Box::new(day_09_mirage_maintenance::DaySolution),
|
||||||
"10" => Box::new(day_10_pipe_maze::DaySolution),
|
"10" => Box::new(day_10_pipe_maze::DaySolution),
|
||||||
|
"11" => Box::new(day_11_cosmic_expantion::DaySolution),
|
||||||
_ => panic!("Invalid day specified"),
|
_ => panic!("Invalid day specified"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue