diff options
Diffstat (limited to 'day3/day3-2.js')
-rw-r--r-- | day3/day3-2.js | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/day3/day3-2.js b/day3/day3-2.js new file mode 100644 index 0000000..a0c558d --- /dev/null +++ b/day3/day3-2.js @@ -0,0 +1,12 @@ +const data = require('./data') +const check = (x, y) => { + let trees = 0, turn = 0; + for(i=0; i<data.length; i=i+y) { + turn !== 0 && data[i][(x * turn)%data[i].length] === "#" && (trees += 1) + turn += 1 + } + return trees +} + +console.log(check(1,1) * check(3,1) * check(5,1) * check(7,1) * check(1,2)) + |