Skip to content

Commit 45c288b

Browse files
feat(2020-day-09): sum min and max from weakness range to solve part 2
1 parent 6bb92a6 commit 45c288b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

2020/day-09/solution.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const fs = require('fs')
22
const path = require('path')
33
const filePath = path.join(__dirname, 'input.txt')
44
const { inputToArray } = require('../../2018/inputParser')
5-
const { findInvalid } = require('./xmasEncryption')
5+
const { findInvalid, findWeaknessRange } = require('./xmasEncryption')
66

77
fs.readFile(filePath, { encoding: 'utf8' }, (err, initData) => {
88
if (err) throw err
@@ -21,9 +21,12 @@ fs.readFile(filePath, { encoding: 'utf8' }, (err, initData) => {
2121

2222
const part2 = () => {
2323
const data = resetInput()
24-
console.debug(data)
25-
return 'No answer yet'
24+
const weakness = findWeaknessRange(data, answers[0])
25+
const arrMax = Math.max(...weakness)
26+
const arrMin = Math.min(...weakness)
27+
return arrMin + arrMax
2628
}
29+
2730
const answers = []
2831
answers.push(part1())
2932
answers.push(part2())

0 commit comments

Comments
 (0)