Skip to content

Commit fb2de9b

Browse files
committed
solved day 7
1 parent d103842 commit fb2de9b

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/2025/day07.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export function part1(input) {
99
if (map[curr][x] === ".") {
1010
next.add(x);
1111
} else {
12-
if (map[curr][x - 1]) next.add(x - 1);
13-
if (map[curr][x + 1]) next.add(x + 1);
12+
next.add(x - 1);
13+
next.add(x + 1);
1414
splits++;
1515
}
1616
});
@@ -27,16 +27,13 @@ export function part2(input) {
2727
let timelines = 1;
2828
while (map[curr]) {
2929
let next = new Map();
30-
function add(x, count) {
31-
let c = next.get(x) || 0;
32-
next.set(x, c + count);
33-
}
30+
let add = (x, count) => next.set(x, (next.get(x) || 0) + count);
3431
beams.forEach((count, x) => {
3532
if (map[curr][x] === ".") {
3633
add(x, count);
3734
} else {
38-
if (map[curr][x - 1]) add(x - 1, count);
39-
if (map[curr][x + 1]) add(x + 1, count);
35+
add(x - 1, count);
36+
add(x + 1, count);
4037
timelines += count;
4138
}
4239
});

0 commit comments

Comments
 (0)