Skip to content

Commit c5e8642

Browse files
committed
feat(04/2025): solve first part
1 parent d5f3f1c commit c5e8642

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
| [Day 1: Secret Entrance](src/solutions/year2025/day01.rs) || 0.144 | - |
1515
| [Day 2: Gift Shop](src/solutions/year2025/day02.rs) | ⭐⭐ | 65.103 | 81.719 |
1616
| [Day 3: Lobby](src/solutions/year2025/day03.rs) | ⭐⭐ | 0.131 | 0.133 |
17-
| [Day 4: Printing Department](src/solutions/year2025/day04.rs) | - | - | - |
17+
| [Day 4: Printing Department](src/solutions/year2025/day04.rs) | | 3.615 | - |
1818

1919
# 2024
2020

src/solutions/year2025/day04.rs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
use crate::solutions::Solution;
2+
use crate::utils::grid::Grid;
23

34
pub struct Day04;
45

56
impl Solution for Day04 {
6-
fn part_one(&self, _input: &str) -> String {
7-
String::from("0")
7+
fn part_one(&self, input: &str) -> String {
8+
const ROLL_OF_PAPER: char = '@';
9+
let grid: Grid<char> = Grid::from(input);
10+
11+
grid.get_all_positions(&ROLL_OF_PAPER)
12+
.iter()
13+
.filter(|p| {
14+
p.adjacent_with_diagonal_vectors()
15+
.iter()
16+
.filter(|adj| grid.is_for_point(&adj.position(), ROLL_OF_PAPER))
17+
.count()
18+
< 4
19+
})
20+
.count()
21+
.to_string()
822
}
923

1024
fn part_two(&self, _input: &str) -> String {
@@ -17,10 +31,19 @@ mod tests {
1731
use crate::solutions::year2025::day04::Day04;
1832
use crate::solutions::Solution;
1933

20-
const EXAMPLE: &str = r#""#;
34+
const EXAMPLE: &str = r#"..@@.@@@@.
35+
@@@.@.@.@@
36+
@@@@@.@.@@
37+
@.@@@@..@.
38+
@@.@@@@.@@
39+
.@@@@@@@.@
40+
.@.@.@.@@@
41+
@.@@@.@@@@
42+
.@@@@@@@@.
43+
@.@.@@@.@."#;
2144

2245
#[test]
2346
fn part_one_example_test() {
24-
assert_eq!("0", Day04.part_one(EXAMPLE));
47+
assert_eq!("13", Day04.part_one(EXAMPLE));
2548
}
2649
}

0 commit comments

Comments
 (0)