Skip to content

Commit 2155634

Browse files
committed
refactor
1 parent bb3a5f7 commit 2155634

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/2025/day03.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ export function part1(input, batteries = 2) {
22
let lines = input.split("\n").map(line => line.split("").map(Number));
33
let voltage = lines.map(line => {
44
let result = 0;
5-
line.push(0);
6-
for (let i = batteries; i > 0; i--) {
7-
let max = Math.max(...line.slice(0, -1 * i));
5+
for (let i = batteries - 1; i >= 0; i--) {
6+
let max = Math.max(...line.slice(0, line.length - i));
87
let index = line.findIndex(x => x === max);
98
line = line.slice(index + 1);
109
result = result * 10 + max;

0 commit comments

Comments
 (0)