mirror of
https://github.com/LeMoonStar/AoC24.git
synced 2025-07-07 17:15:30 +02:00
✨ Day 4: Solved part 2!
This commit is contained in:
parent
134512e4ba
commit
2d89799e44
2 changed files with 48 additions and 5 deletions
|
@ -3,8 +3,8 @@
|
|||
[](https://adventofcode.com/2024/about)
|
||||
[](https://en.wikipedia.org/wiki/Rust_(programming_language))
|
||||
[](https://mit-license.org/)
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
> ⚠️ This README is copied from my previous years solution. It is not fully adopted to 2024 yet.
|
||||
|
||||
|
|
|
@ -116,6 +116,38 @@ impl LetterWall {
|
|||
directions
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
fn is_cross_mas(&self, x: usize, y: usize) -> bool {
|
||||
match(
|
||||
self.at( x, y), self.at( x+1, y), self.at( x+2, y),
|
||||
self.at( x, y+1), self.at( x+1, y+1), self.at( x+2, y+1),
|
||||
self.at( x, y+2), self.at( x+1, y+2), self.at( x+2, y+2)
|
||||
) {
|
||||
(
|
||||
Some('M'), _,Some('S'),
|
||||
_, Some('A'), _,
|
||||
Some('M'), _, Some('S'),
|
||||
) => true,
|
||||
(
|
||||
Some('S'), _,Some('S'),
|
||||
_, Some('A'), _,
|
||||
Some('M'), _, Some('M'),
|
||||
) => true,
|
||||
(
|
||||
Some('M'), _,Some('M'),
|
||||
_, Some('A'), _,
|
||||
Some('S'), _, Some('S'),
|
||||
) => true,
|
||||
(
|
||||
Some('S'), _,Some('M'),
|
||||
_, Some('A'), _,
|
||||
Some('S'), _, Some('M'),
|
||||
) => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn count_xmas(&self) -> u64 {
|
||||
let mut count = 0;
|
||||
for y in 0..self.0.len() {
|
||||
|
@ -125,6 +157,18 @@ impl LetterWall {
|
|||
}
|
||||
return count as u64;
|
||||
}
|
||||
|
||||
pub fn count_cross_mas(&self) -> u64 {
|
||||
let mut count = 0;
|
||||
for y in 0..self.0.len() {
|
||||
for x in 0..self.0[0].len() {
|
||||
if self.is_cross_mas(x, y) {
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count as u64;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for LetterWall {
|
||||
|
@ -141,7 +185,7 @@ impl DayImpl<Data> for Day<CURRENT_DAY> {
|
|||
}
|
||||
|
||||
fn expected_results() -> (Answer, Answer) {
|
||||
(Answer::Number(18), Answer::Number(0))
|
||||
(Answer::Number(18), Answer::Number(9))
|
||||
}
|
||||
|
||||
fn init(input: &str) -> (Self, Data) {
|
||||
|
@ -149,11 +193,10 @@ impl DayImpl<Data> for Day<CURRENT_DAY> {
|
|||
}
|
||||
|
||||
fn one(&self, data: &mut Data) -> Answer {
|
||||
// NOTE TO SELF: Actual result above 2334
|
||||
Answer::Number(data.count_xmas())
|
||||
}
|
||||
|
||||
fn two(&self, data: &mut Data) -> Answer {
|
||||
Answer::Number(0)
|
||||
Answer::Number(data.count_cross_mas())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue