2020 day 3 - feels good to be back
This commit is contained in:
parent
de2fa19311
commit
77b47a86e5
4 changed files with 378 additions and 0 deletions
23
2020/03/part2.js
Normal file
23
2020/03/part2.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
const fs = require('fs');
|
||||
|
||||
const data = fs.readFileSync('input.txt', 'utf-8');
|
||||
const lines = data.split('\n');
|
||||
|
||||
console.log()
|
||||
const width = lines[0].length
|
||||
// lets do it recursively why not
|
||||
function trees(x, y, slopex, slopey) {
|
||||
// escape case : bottom row
|
||||
if (y >= lines.length - 1) {
|
||||
return lines[y][x % width]=="#"
|
||||
}
|
||||
// haha javascript bool to int type casting go brrr
|
||||
return (lines[y][x % width]=="#") + trees(x+slopex, y+slopey, slopex, slopey)
|
||||
}
|
||||
|
||||
// got lucky with this star lol
|
||||
console.log(trees(0,0,1,1)
|
||||
*trees(0,0,3,1)
|
||||
*trees(0,0,5,1)
|
||||
*trees(0,0,7,1)
|
||||
*trees(0,0,1,2))
|
Loading…
Add table
Add a link
Reference in a new issue