diff --git a/2021/day-05/solution.js b/2021/day-05/solution.js index 232d95e..1290e5e 100644 --- a/2021/day-05/solution.js +++ b/2021/day-05/solution.js @@ -13,8 +13,9 @@ fs.readFile(filePath, { encoding: 'utf8' }, (err, initData) => { return JSON.parse(JSON.stringify(initData)) } - const part1 = () => { + const task = (supportDiagonals) => { const data = resetInput() + // Allocate map const max = data.reduce((max, curr) => { max[0] = Math.max(max[0], curr[0], curr[2]) // find the maximum X value @@ -22,24 +23,25 @@ fs.readFile(filePath, { encoding: 'utf8' }, (err, initData) => { return max }, [0, 0]) - console.debug(max) - let map = [...new Array(max[1] + 1)].map(() => { return [...new Array(max[0] + 1)].map(() => 0) }) data.forEach((line) => { - map = chartLine(map, ...line) + map = chartLine(map, ...line, supportDiagonals) }) return countIntersections(map, 2) } + const part1 = () => { + return task(false) + } + const part2 = () => { - const data = resetInput() - console.debug(data) - return 'No answer yet' + return task(true) } + const answers = [] answers.push(part1()) answers.push(part2())