From 5a173732440b5a827fb592862957b24f789d87bb Mon Sep 17 00:00:00 2001 From: Fabian Schmidt Date: Wed, 4 Dec 2024 11:19:28 +0100 Subject: [PATCH] y2024d4 --- Cargo.lock | 1 + y2024/Cargo.toml | 1 + y2024/resources/4_input.txt | 140 ++++++++++++++++++++++++++++++ y2024/src/bin/d4.rs | 20 +++++ y2024/src/days/d4.rs | 164 ++++++++++++++++++++++++++++++++++++ y2024/src/days/mod.rs | 2 + 6 files changed, 328 insertions(+) create mode 100644 y2024/resources/4_input.txt create mode 100644 y2024/src/bin/d4.rs create mode 100644 y2024/src/days/d4.rs diff --git a/Cargo.lock b/Cargo.lock index 4fc2597..cf62ab4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -121,4 +121,5 @@ name = "y2024" version = "0.1.0" dependencies = [ "regex", + "utils", ] diff --git a/y2024/Cargo.toml b/y2024/Cargo.toml index e019528..e774106 100644 --- a/y2024/Cargo.toml +++ b/y2024/Cargo.toml @@ -5,3 +5,4 @@ edition = "2021" [dependencies] regex = "1.11.1" +utils = { workspace = true } diff --git a/y2024/resources/4_input.txt b/y2024/resources/4_input.txt new file mode 100644 index 0000000..a89f70c --- /dev/null +++ b/y2024/resources/4_input.txt @@ -0,0 +1,140 @@ +MMSMXMSASXMXAXMAXSASXXXMASAMXSMMMXMMXMXMASMXMASMSMXSSXMASXSMMSASMSAXAMXMAMMMSAMXXXMAMSMXMMMXMASXMAXXMMMXMMSAMXAMMSMSSMSMMMSMMXSXXAXMXSAXMASX +XAXMASMXMASASXSXAMAMXMXMAXAMXSASAMXMAMAMSAMSSXMMAXASXAMAMSMAXMXMASMSASASASAAMAMXSMSMSAXAAXXAMSSMXMXSMAMXXAXAXXASXAMAAXAAXXMAXAXXMMSSMSSXSASA +XMASXXXASAMAMASMMMAMMSASXSXMASAMMAXSAXXXMASXMASMSMMMMXMAXAXXMSAMXMAAXSASASMXSAMAAAAXSASMMMMMSAXMASAMSAMSMMSAMSAMAMMXSMSXMASXMASAASA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MAX diff --git a/y2024/src/bin/d4.rs b/y2024/src/bin/d4.rs new file mode 100644 index 0000000..c6a2a62 --- /dev/null +++ b/y2024/src/bin/d4.rs @@ -0,0 +1,20 @@ +use std::fs; + +use y2024::days::d4; + +fn main() { + part1(); + part2(); +} + +fn part1() { + let root = env!("CARGO_MANIFEST_DIR"); + let content = fs::read_to_string(format!("{root}/resources/4_input.txt")).unwrap(); + println!("{}", d4::process_part1(&content)); +} + +fn part2() { + let root = env!("CARGO_MANIFEST_DIR"); + let content = fs::read_to_string(format!("{root}/resources/4_input.txt")).unwrap(); + println!("{}", d4::process_part2(&content)); +} diff --git a/y2024/src/days/d4.rs b/y2024/src/days/d4.rs new file mode 100644 index 0000000..fc96b5c --- /dev/null +++ b/y2024/src/days/d4.rs @@ -0,0 +1,164 @@ +use std::cmp; + +use utils::grid::Grid; + +pub fn process_part1(input: &str) -> i32 { + let grid = input + .lines() + .map(|line| { + line.chars() + .map(|char| char.to_string()) + .collect::>() + }) + .collect::>>(); + let mut grid = Grid::new(grid).unwrap(); + let mut res = 0; + for row in &grid.rows { + let row = row.join(""); + res += row.matches("XMAS").count(); + res += row.matches("SAMX").count(); + } + for diag_grave in grid.get_diagonals_grave() { + let diag_grave = diag_grave.join(""); + res += diag_grave.matches("XMAS").count(); + res += diag_grave.matches("SAMX").count(); + } + for diag_aigu in grid.get_diagonals_aigu() { + let diag_aigu = diag_aigu.join(""); + res += diag_aigu.matches("XMAS").count(); + res += diag_aigu.matches("SAMX").count(); + } + for col in grid.rotate_90().rows { + let col = col.join(""); + res += col.matches("XMAS").count(); + res += col.matches("SAMX").count(); + } + res.try_into().unwrap() +} + +pub fn process_part2(input: &str) -> i32 { + let grid = input + .lines() + .map(|line| { + line.chars() + .map(|char| char.to_string()) + .collect::>() + }) + .collect::>>(); + let grid = Grid::new(grid).unwrap(); + let mut res = 0; + // Irrelevant as this finds + not x + // But actually helpful as I can just create diagonals, left and right pad to create a square + // grid and apply this + //for (row_idx, row) in grid.rows.iter().enumerate() { + // if row_idx == 0 || row_idx == grid.rows.len() - 1 { + // continue; + // } + // let row = row.join(""); + // for (match_idx, _) in row.match_indices("MAS") { + // let above = grid.rows[row_idx - 1][match_idx + 1].clone(); + // let below = grid.rows[row_idx + 1][match_idx + 1].clone(); + // if (above == "M" && below == "S") || (above == "S" && below == "M") { + // res += 1; + // } + // } + // for (match_idx, _) in row.match_indices("SAM") { + // let above = grid.rows[row_idx - 1][match_idx + 1].clone(); + // let below = grid.rows[row_idx + 1][match_idx + 1].clone(); + // if (above == "M" && below == "S") || (above == "S" && below == "M") { + // res += 1; + // } + // } + //} + let diagonals = grid.get_diagonals_grave(); + // new width is as long as the longest diagonal + // the diagonal length goes from 1..min(grid width, grid height) + // then pad on each side by difference / 2 + let new_width = cmp::min(grid.width as usize, grid.rows.len()); + let mut even_grid = Vec::new(); + let mut odd_grid = Vec::new(); + for diagonal in diagonals { + let diagonal_length = diagonal.len(); + let pad = (new_width - diagonal_length) / 2; + let new_row = [ + vec!["#".to_string(); pad], + diagonal, + vec!["#".to_string(); pad], + ] + .concat(); + if diagonal_length % 2 == 0 { + even_grid.push(new_row); + } else { + odd_grid.push(new_row); + } + } + for (row_idx, row) in even_grid.iter().enumerate() { + if row_idx == 0 || row_idx == even_grid.len() - 1 { + continue; + } + let row = row.join(""); + for (match_idx, _) in row.match_indices("MAS") { + let above = even_grid[row_idx - 1][match_idx + 1].clone(); + let below = even_grid[row_idx + 1][match_idx + 1].clone(); + if (above == "M" && below == "S") || (above == "S" && below == "M") { + res += 1; + } + } + for (match_idx, _) in row.match_indices("SAM") { + let above = even_grid[row_idx - 1][match_idx + 1].clone(); + let below = even_grid[row_idx + 1][match_idx + 1].clone(); + if (above == "M" && below == "S") || (above == "S" && below == "M") { + res += 1; + } + } + } + for (row_idx, row) in odd_grid.iter().enumerate() { + if row_idx == 0 || row_idx == odd_grid.len() - 1 { + continue; + } + let row = row.join(""); + for (match_idx, _) in row.match_indices("MAS") { + let above = odd_grid[row_idx - 1][match_idx + 1].clone(); + let below = odd_grid[row_idx + 1][match_idx + 1].clone(); + if (above == "M" && below == "S") || (above == "S" && below == "M") { + res += 1; + } + } + for (match_idx, _) in row.match_indices("SAM") { + let above = odd_grid[row_idx - 1][match_idx + 1].clone(); + let below = odd_grid[row_idx + 1][match_idx + 1].clone(); + if (above == "M" && below == "S") || (above == "S" && below == "M") { + res += 1; + } + } + } + res +} + +#[cfg(test)] +mod tests { + use super::*; + + const INPUT: &str = "MMMSXXMASM +MSAMXMSMSA +AMXSXMAAMM +MSAMASMSMX +XMASAMXAMM +XXAMMXXAMA +SMSMSASXSS +SAXAMASAAA +MAMMMXMMMM +MXMXAXMASX"; + + #[test] + fn part1() { + let result = process_part1(INPUT); + assert_eq!(result, 18); + } + + #[test] + fn part2() { + let result = process_part2(INPUT); + assert_eq!(result, 9); + } +} diff --git a/y2024/src/days/mod.rs b/y2024/src/days/mod.rs index 4cee8c2..69d8311 100644 --- a/y2024/src/days/mod.rs +++ b/y2024/src/days/mod.rs @@ -3,3 +3,5 @@ pub mod d1; pub mod d2; pub mod d3; + +pub mod d4;