File tree Expand file tree Collapse file tree 2 files changed +28
-5
lines changed
Expand file tree Collapse file tree 2 files changed +28
-5
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 11use crate :: solutions:: Solution ;
2+ use crate :: utils:: grid:: Grid ;
23
34pub struct Day04 ;
45
56impl 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}
You can’t perform that action at this time.
0 commit comments