This commit is contained in:
Fabian Schmidt 2024-12-04 11:19:28 +01:00
parent dafe576fc9
commit 29a122c3ff
6 changed files with 328 additions and 0 deletions

1
Cargo.lock generated
View File

@ -121,4 +121,5 @@ name = "y2024"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"regex", "regex",
"utils",
] ]

View File

@ -5,3 +5,4 @@ edition = "2021"
[dependencies] [dependencies]
regex = "1.11.1" regex = "1.11.1"
utils = { workspace = true }

140
y2024/resources/4_input.txt Normal file
View File

@ -0,0 +1,140 @@
MMSMXMSASXMXAXMAXSASXXXMASAMXSMMMXMMXMXMASMXMASMSMXSSXMASXSMMSASMSAXAMXMAMMMSAMXXXMAMSMXMMMXMASXMAXXMMMXMMSAMXAMMSMSSMSMMMSMMXSXXAXMXSAXMASX
XAXMASMXMASASXSXAMAMXMXMAXAMXSASAMXMAMAMSAMSSXMMAXASXAMAMSMAXMXMASMSASASASAAMAMXSMSMSAXAAXXAMSSMXMXSMAMXXAXAXXASXAMAAXAAXXMAXAXXMMSSMSSXSASA
XMASXXXASAMAMASMMMAMMSASXSXMASAMMAXSAXXXMASXMASMSMMMMXMAXAXXMSAMXMAAXSASASMXSAMAAAAXSASMMMMMSAXMASAMSAMSMMSAMSAMAMMXSMSXMASXMASAASAAXMAMMAMM
SSMSMSSXMMMAMSMAXMAXXMAMMAMSXMSMMMXMAMSXSSMXSAMXXAASXMSMSMSMMSXSAMMMMMAMXMXAMASXMSMMMXMAAAXMMMSMAMAMMMMAAXMAMSAMXXXMAMAASXMAAXXMXMSMMMSMMAMX
XXAXAAAMMSSMMXASXSMSSMAMSAMXAXXXASMMSMSASAMXMASMSXMXAAXXAAAAASASAMAXSMSMSSMSSMAAXAXAMXMMMSXXAXAMSSSMMSSMSMSAMSMMSMXMMXSMSASXSXMMSMAMAAMAMASX
MMMMSMMAAAAMASXMAAXAAMSMXAMSAMXSMXAAAAMMMAMASMMMASXSMMSSSSSSMMMMMSAMSXASAAAAAMMXSXSMXSSXSAXAM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XXXAMSMSSSMXMAMSMMMSSMAMAAMXSASASASMSSXSXAASMSMSSMMMMMXXASXMSSMMSSSMMXXAASXSAMXXXAXXXAAXAMMSMSAAMXMMXAASMSMMAAMXSAXMASXMA
MAMSSXMAMXXAMAXMMSSMAMXXXAXMAMAMXAXAAAAAXAMMXXXMAMAMAXAMMAMASXMAAXAXSXXXAXMAXSAAXXAXAAASMMSXSASXSSXSMSMSMMXAMXAAXXMXAMXSSMMMAAMMMSXMMXSSMASX
XMSAAMSMSSSSMSMSAAAXXSMMMSMXAMMSMAMSMMSSSMSMSAMXSMSMSMASMMMAMMMSMMMSXSMMSSMMMMMMSMMMMSMMAAXAMAMAMAASAAXMAXSASXXSMAMSMMAAAASXSSMMMSAXAASASAMM
SXMMSMAAAAAMAAAMMSMMSXAAAAASMSAXMAMAAMAAAAAASMAAXAXAXSAMAAMASXXMASXSAMXAAAAAXXSAMXSAMXXMMMMAMAMAMMSMSMMSAMSAMAXXMXMASMXSSMMMXAAAASMMMSSMMMSA
XXXXXXMSMMMMMMSMXAXMASXMSXMAAMMSSMSSSMXSMMMMMMSAMSMMMMMSSMSXSASXMMSMAMMMSSMMAMXXMASXSAXMAMSXSXSXSXXMAMXMXXMMMAMXAXMAMSAAXMXMASXMMSXXMAMXXMAX

20
y2024/src/bin/d4.rs Normal file
View File

@ -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));
}

164
y2024/src/days/d4.rs Normal file
View File

@ -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::<Vec<String>>()
})
.collect::<Vec<Vec<String>>>();
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::<Vec<String>>()
})
.collect::<Vec<Vec<String>>>();
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);
}
}

View File

@ -3,3 +3,5 @@ pub mod d1;
pub mod d2; pub mod d2;
pub mod d3; pub mod d3;
pub mod d4;