Skip to content

Commit 41736ff

Browse files
feat(2020-day-03): calculate tree collisions for multiple slopes
Solution for part 2
1 parent b25ec56 commit 41736ff

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy