Skip to content

Commit 427a5a9

Browse files
feat(2018 day-11): Compare across any size squares
1 parent 1dc7b24 commit 427a5a9

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

2018/day-11/solution.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const { dynamicSort } = require('../day-04/helpers')
12
const { Rack } = require('./fuel-cells')
23
const serial = 1133 // From puzzle input
34
const size = [300, 300]
@@ -6,7 +7,22 @@ const squareSize = [3, 3]
67
let powerBank = new Rack(serial, size)
78
powerBank.tallySquares(squareSize)
89
const answer = powerBank.getCellsByPower(squareSize)[0].coords
9-
const answer2 = ''
10+
11+
const anySizeSquares = []
12+
for (let dial = 1; dial <= 5; dial++) {
13+
powerBank.tallySquares([dial, dial])
14+
let bestOfSizeX = powerBank.getCellsByPower(squareSize)[0]
15+
anySizeSquares.push({
16+
coords: bestOfSizeX.coords,
17+
power: bestOfSizeX.squareTotal,
18+
size: dial
19+
})
20+
}
21+
22+
const bestOfAnySize = anySizeSquares.sort(dynamicSort('-power'))[0]
23+
let answer2 = bestOfAnySize.coords
24+
answer2.push(bestOfAnySize.size)
25+
1026
console.log(`-- Part 1 --`)
1127
console.log(`Answer: ${answer}`)
1228
console.log(`-- Part 2 --`)

0 commit comments

Comments
 (0)