File tree Expand file tree Collapse file tree 2 files changed +56
-1
lines changed
AdventOfCode/aoc-2025-deno Expand file tree Collapse file tree 2 files changed +56
-1
lines changed Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ while (true) {
6666 }
6767
6868 if ( accessible . length == 0 ) break
69-
69+
7070 total += accessible . length
7171
7272 for ( const e of accessible ) {
Original file line number Diff line number Diff line change 1+ const input = Deno . readTextFileSync ( "./day06.txt" ) . trim ( ) . split ( "\n" )
2+
3+ const split = input . map ( l => l . split ( / + / ) )
4+
5+ let total = 0
6+
7+ for ( let column = 0 ; column < split [ 0 ] . length ; column ++ ) {
8+ const operation = split [ 4 ] [ column ]
9+
10+ let result = operation == "*" ? 1 : 0
11+ for ( let i = 0 ; i < 4 ; i ++ ) {
12+ const value = parseInt ( split [ i ] [ column ] )
13+ if ( operation == "*" ) {
14+ result *= value
15+ } else {
16+ result += value
17+ }
18+ }
19+ total += result
20+ }
21+
22+ console . log ( total )
23+
24+ total = 0
25+
26+ const operators = split [ 4 ]
27+ const columnWise : number [ ] [ ] = [ [ ] ]
28+
29+ for ( let column = 0 ; column < input [ 0 ] . length ; column ++ ) {
30+ let topToBottom = ""
31+ for ( let row = 0 ; row < 4 ; row ++ ) [
32+ topToBottom += input [ row ] [ column ]
33+ ]
34+
35+ const value = parseInt ( topToBottom . trim ( ) )
36+ if ( Number . isNaN ( value ) ) {
37+ columnWise . push ( [ ] )
38+ } else {
39+ columnWise [ columnWise . length - 1 ] . push ( value )
40+ }
41+ }
42+
43+ for ( const [ i , operator ] of operators . entries ( ) ) {
44+ let result = operator == "*" ? 1 : 0
45+ for ( const v of columnWise [ i ] ) {
46+ if ( operator == "*" ) {
47+ result *= v
48+ } else {
49+ result += v
50+ }
51+ }
52+ total += result
53+ }
54+
55+ console . log ( total )
You can’t perform that action at this time.
0 commit comments