summaryrefslogtreecommitdiffstats
path: root/day3/day3-2.js
diff options
context:
space:
mode:
authorGravatar Piotr Russ <piotr.russ@betvictor.com> 2020-12-07 22:53:36 +0100
committerGravatar Piotr Russ <piotr.russ@betvictor.com> 2020-12-07 22:53:36 +0100
commit3700a9063725b001267730d6586d9cf905476cbb (patch)
treeea80cec1f3c24a940abf0527981625bec08a46e8 /day3/day3-2.js
parent5e34312e42721aae0d8919df7ef31ffaff435555 (diff)
downloadadvent_of_code_2020-3700a9063725b001267730d6586d9cf905476cbb.tar.gz
advent_of_code_2020-3700a9063725b001267730d6586d9cf905476cbb.tar.bz2
advent_of_code_2020-3700a9063725b001267730d6586d9cf905476cbb.zip
day3
Diffstat (limited to 'day3/day3-2.js')
-rw-r--r--day3/day3-2.js12
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))
+