Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 1x 1x 1x 1x | const { getPerformanceMade, extractData } = require('./puzzle1')
const extractAndJoinData = (fileInput) => {
const [time, distance] = extractData(fileInput)
return [[parseInt(time.join(''))], [parseInt(distance.join(''))]]
}
const resolvePuzzle = (inputFile) => {
const possibilities = []
const [time, distance] = extractAndJoinData(inputFile)
for (let i = 0; i < time.length; i++) {
let waysToWin = 0
for (let j = 0; j < time[i]; j++) {
const distanceMade = getPerformanceMade(j, time[i])
if (distanceMade > distance[i]) {
waysToWin++
}
}
possibilities.push(waysToWin)
}
return possibilities.reduce((prev, curr) => prev * curr)
}
module.exports = { resolvePuzzle }
|