Skip to content

Commit 585cbbe

Browse files
feat(2018 day-11): hackish solution identified by noticing a pattern in the logs and forcing an arbitrary negative condition
1 parent d6e652c commit 585cbbe

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

2018/day-11/solution.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ console.log(`-- Part 1 --`)
1414
console.log(`Answer: ${answer}`)
1515

1616
const anySizeSquares = []
17+
let negativeCounter = 0
1718
for (let dial = 1; dial <= 300; dial++) {
18-
console.log(`Measuring power with dial at ${dial}`)
1919
// powerBank.tallySquares([dial, dial])
2020
// let bestOfSizeX = powerBank.getCellsByPower(squareSize)[0]
2121
// anySizeSquares.push({
@@ -24,11 +24,21 @@ for (let dial = 1; dial <= 300; dial++) {
2424
// size: dial
2525
// })
2626
const max = powerBank.findMaxSquare([dial, dial])
27+
console.log(`Max power whith dial at ${dial} is ${max.power}`)
28+
2729
anySizeSquares.push({
2830
coords: powerBank.cells[max.idx].coords,
2931
power: max.power,
3032
size: dial
3133
})
34+
35+
// Watching the log, the power seems to go up as the grid size goes up, but reaches
36+
// a limit at which point it drops of forever. Therefore, let's cap it when 5 sizes in
37+
// a row have negative power outputs
38+
if (max.power < 0) { negativeCounter++ }
39+
if (negativeCounter >= 5) {
40+
break
41+
}
3242
}
3343

3444
const bestOfAnySize = anySizeSquares.sort(dynamicSort('-power'))[0]

0 commit comments

Comments
 (0)