Skip to content

Commit eef9776

Browse files
day6
1 parent 28b10d2 commit eef9776

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

AdventOfCode/aoc-2025-deno/day04.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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) {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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)

0 commit comments

Comments
 (0)