Skip to content

Commit dfbfec2

Browse files
feat[2020-day-03]: calculate tree collisions for multiple slopes
Solution for part 2
1 parent de18ecd commit dfbfec2

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

2020/day-03/solution.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,20 @@ 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 slopes = [
25+
[1, 1],
26+
[3, 1], // Same as default
27+
[5, 1],
28+
[7, 1],
29+
[1, 2]
30+
]
31+
// Multiple the results of multiple slopes
32+
return slopes.reduce((itr, slope) => {
33+
return itr * countTreesOnRoute({
34+
map: { rows: data },
35+
slope
36+
})
37+
}, 1)
2638
}
2739
const answers = []
2840
answers.push(part1())

0 commit comments

Comments
 (0)