File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ Solutions for [Advent of Code](https://adventofcode.com/) in [Rust](https://www.
1010
1111| Year | Completed |
1212| :---: | :---: |
13- | [ 2025] ( aoc2025 ) | 12 /24 |
13+ | [ 2025] ( aoc2025 ) | 14 /24 |
1414| [ 2024] ( aoc2024 ) | 50/50 |
1515| [ 2023] ( aoc2023 ) | 50/50 |
1616| [ 2015] ( aoc2015 ) | 12/50 |
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ Solutions for [Advent of Code](https://adventofcode.com/) in [Rust](https://www.
1212| [ Day 4] ( https://adventofcode.com/2025/day/4 ) | [ code] ( src/bin/04.rs ) | ⭐ | ⭐ |
1313| [ Day 5] ( https://adventofcode.com/2025/day/5 ) | [ code] ( src/bin/05.rs ) | ⭐ | ⭐ |
1414| [ Day 6] ( https://adventofcode.com/2025/day/6 ) | [ code] ( src/bin/06.rs ) | ⭐ | ⭐ |
15- | [ Day 7] ( https://adventofcode.com/2025/day/7 ) | [ code] ( src/bin/07.rs ) | _ | _ |
15+ | [ Day 7] ( https://adventofcode.com/2025/day/7 ) | [ code] ( src/bin/07.rs ) | ⭐ | ⭐ |
1616| [ Day 8] ( https://adventofcode.com/2025/day/8 ) | [ code] ( src/bin/08.rs ) | _ | _ |
1717| [ Day 9] ( https://adventofcode.com/2025/day/9 ) | [ code] ( src/bin/09.rs ) | _ | _ |
1818| [ Day 10] ( https://adventofcode.com/2025/day/10 ) | [ code] ( src/bin/10.rs ) | _ | _ |
Original file line number Diff line number Diff line change 1+ .......S.......
2+ ...............
3+ .......^.......
4+ ...............
5+ ......^.^......
6+ ...............
7+ .....^.^.^.....
8+ ...............
9+ ....^.^...^....
10+ ...............
11+ ...^.^...^.^...
12+ ...............
13+ ..^...^.....^..
14+ ...............
15+ .^.^.^.^.^...^.
16+ ...............
Original file line number Diff line number Diff line change 1+ use aoc_utils:: * ;
2+
3+ advent_of_code:: solution!( 7 ) ;
4+
5+ pub fn part_one ( input : & str ) -> Option < u64 > {
6+ let mut map = input. c_map ( ) ;
7+ let mut splits = 0 ;
8+ for r in 1 ..map. len ( ) {
9+ for c in 0 ..map[ r] . len ( ) {
10+ let prev = map[ r - 1 ] [ c] ;
11+ let curr = map[ r] [ c] ;
12+ match ( prev, curr) {
13+ ( 'S' | '|' , '.' ) => map[ r] [ c] = '|' ,
14+ ( 'S' | '|' , '^' ) => {
15+ splits += 1 ;
16+ map[ r] [ c - 1 ] = '|' ;
17+ map[ r] [ c + 1 ] = '|' ;
18+ }
19+ _ => ( ) ,
20+ }
21+ }
22+ }
23+ Some ( splits)
24+ }
25+
26+ pub fn part_two ( input : & str ) -> Option < u64 > {
27+ let map = input. c_map ( ) ;
28+ let mut map_counts = vec ! [ vec![ 0 ; map[ 0 ] . len( ) ] ; map. len( ) ] ;
29+ for r in 0 ..map. len ( ) {
30+ for c in 0 ..map[ r] . len ( ) {
31+ let prev = map_counts[ if r > 0 { r - 1 } else { 0 } ] [ c] ;
32+ let curr = map[ r] [ c] ;
33+ match ( prev, curr) {
34+ ( _, 'S' ) => map_counts[ r] [ c] = 1 ,
35+ ( x, '.' ) if x > 0 => {
36+ map_counts[ r] [ c] += map_counts[ r - 1 ] [ c] ;
37+ }
38+ ( x, '^' ) if x > 0 => {
39+ map_counts[ r] [ c - 1 ] += map_counts[ r - 1 ] [ c] ;
40+ map_counts[ r] [ c + 1 ] += map_counts[ r - 1 ] [ c] ;
41+ }
42+ _ => ( ) ,
43+ }
44+ }
45+ }
46+ let timelines = map_counts[ map_counts. len ( ) - 1 ] . iter ( ) . sum ( ) ;
47+ Some ( timelines)
48+ }
49+
50+ #[ cfg( test) ]
51+ mod tests {
52+ use super :: * ;
53+
54+ #[ test]
55+ fn test_part_one ( ) {
56+ let result = part_one ( & advent_of_code:: template:: read_file ( "examples" , DAY ) ) ;
57+ assert_eq ! ( result, Some ( 21 ) ) ;
58+ }
59+
60+ #[ test]
61+ fn test_part_two ( ) {
62+ let result = part_two ( & advent_of_code:: template:: read_file ( "examples" , DAY ) ) ;
63+ assert_eq ! ( result, Some ( 40 ) ) ;
64+ }
65+ }
You can’t perform that action at this time.
0 commit comments