File tree Expand file tree Collapse file tree
src/AdventOfCode.Puzzles/2025/06 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+
2+ namespace AdventOfCode . Puzzles . _2025 . _06 . Part1 ;
3+
4+ public class AoC2025Day6Part1 : IPuzzleSolution
5+ {
6+ public async Task < string > SolveAsync ( StreamReader inputReader )
7+ {
8+ var problems = new List < string [ ] > ( ) ;
9+ var lines = await inputReader . ReadAllLinesAsync ( ) ;
10+ foreach ( var line in lines )
11+ {
12+ var parts = line . Split ( ' ' , StringSplitOptions . RemoveEmptyEntries | StringSplitOptions . TrimEntries ) ;
13+ problems . Add ( parts ) ;
14+ }
15+
16+ ulong total = 0 ;
17+ for ( int i = 0 ; i < problems [ 0 ] . Length ; i ++ )
18+ {
19+ var multiply = problems [ problems . Count - 1 ] [ i ] == "*" ;
20+ var currentResult = multiply ? 1UL : 0 ;
21+ for ( int line = 0 ; line < problems . Count - 1 ; line ++ )
22+ {
23+ var number = ulong . Parse ( problems [ line ] [ i ] ) ;
24+ if ( multiply )
25+ {
26+ currentResult *= number ;
27+ }
28+ else
29+ {
30+ currentResult += number ;
31+ }
32+ }
33+
34+ total += currentResult ;
35+ }
36+
37+ return total . ToString ( ) ;
38+ }
39+ }
Original file line number Diff line number Diff line change 1+ namespace AdventOfCode . Puzzles . _2025 . _06 . Part2 ;
2+
3+ public class AoC2025Day6Part2 : IPuzzleSolution
4+ {
5+ public async Task < string > SolveAsync ( StreamReader inputReader )
6+ {
7+ var problems = new List < string [ ] > ( ) ;
8+ var lines = await inputReader . ReadAllLinesAsync ( ) ;
9+
10+ var operatorsLine = lines [ lines . Count - 1 ] ;
11+ ulong gradTotal = 0 ;
12+
13+ var startIndex = 0 ;
14+ do
15+ {
16+ var multiply = operatorsLine [ startIndex ] == '*' ;
17+ ulong currentTotal = multiply ? 1UL : 0 ;
18+
19+ var endIndex = operatorsLine . IndexOfAny ( new [ ] { '+' , '*' } , startIndex + 1 ) ;
20+ if ( endIndex == - 1 )
21+ {
22+ endIndex = operatorsLine . Length + 1 ;
23+ }
24+
25+ for ( var currentColumn = endIndex - 2 ; currentColumn >= startIndex ; currentColumn -- )
26+ {
27+ var currentNumber = 0UL ;
28+ for ( var currentRow = 0 ; currentRow < lines . Count - 1 ; currentRow ++ )
29+ {
30+ var character = lines [ currentRow ] [ currentColumn ] ;
31+ if ( char . IsDigit ( character ) )
32+ {
33+ var number = ( ulong ) ( character - '0' ) ;
34+ currentNumber *= 10 ;
35+ currentNumber += number ;
36+ }
37+ }
38+
39+ if ( multiply )
40+ {
41+ currentTotal *= currentNumber ;
42+ }
43+ else
44+ {
45+ currentTotal += currentNumber ;
46+ }
47+ }
48+ gradTotal += currentTotal ;
49+ startIndex = endIndex ;
50+ } while ( startIndex < operatorsLine . Length ) ;
51+
52+ return gradTotal . ToString ( ) ;
53+ }
54+ }
Original file line number Diff line number Diff line change 1+ 123 328 51 64
2+ 45 64 387 23
3+ 6 98 215 314
4+ * + * +
You can’t perform that action at this time.
0 commit comments