We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent bb3a5f7 commit 2155634Copy full SHA for 2155634
src/2025/day03.js
@@ -2,9 +2,8 @@ export function part1(input, batteries = 2) {
2
let lines = input.split("\n").map(line => line.split("").map(Number));
3
let voltage = lines.map(line => {
4
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));
+ for (let i = batteries - 1; i >= 0; i--) {
+ let max = Math.max(...line.slice(0, line.length - i));
8
let index = line.findIndex(x => x === max);
9
line = line.slice(index + 1);
10
result = result * 10 + max;
0 commit comments