File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -14,8 +14,8 @@ console.log(`-- Part 1 --`)
1414console . log ( `Answer: ${ answer } ` )
1515
1616const anySizeSquares = [ ]
17+ let negativeCounter = 0
1718for ( 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
3444const bestOfAnySize = anySizeSquares . sort ( dynamicSort ( '-power' ) ) [ 0 ]
You can’t perform that action at this time.
0 commit comments