summaryrefslogtreecommitdiffstats
path: root/day2/day2-2.js
diff options
context:
space:
mode:
authorGravatar Piotr Russ <piotr.russ@betvictor.com> 2020-12-07 22:36:36 +0100
committerGravatar Piotr Russ <piotr.russ@betvictor.com> 2020-12-07 22:36:36 +0100
commit5e34312e42721aae0d8919df7ef31ffaff435555 (patch)
tree8c37ef6255c0973f205308b4288e6312ddc6b732 /day2/day2-2.js
parent62493a5b11085b8214188e0b9cee3aae24302c65 (diff)
downloadadvent_of_code_2020-5e34312e42721aae0d8919df7ef31ffaff435555.tar.gz
advent_of_code_2020-5e34312e42721aae0d8919df7ef31ffaff435555.tar.bz2
advent_of_code_2020-5e34312e42721aae0d8919df7ef31ffaff435555.zip
day2
Diffstat (limited to 'day2/day2-2.js')
-rw-r--r--day2/day2-2.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/day2/day2-2.js b/day2/day2-2.js
new file mode 100644
index 0000000..d9848c3
--- /dev/null
+++ b/day2/day2-2.js
@@ -0,0 +1,14 @@
+const data = require('./data')
+const checkPass = (query) => {
+ const first = (parseInt(query.split("-")[0]) - 1)
+ const second = (parseInt(query.split("-")[1].split(" ")[0]) - 1)
+ const letter = query.split(" ")[1].split(":")[0]
+ const pass = query.split(" ")[2]
+
+ return pass[first] === letter && pass[second] !== letter
+ || pass[first] !== letter && pass[second] === letter
+}
+
+let valid = 0
+data.forEach(q => checkPass(q) && (valid += 1))
+console.log(valid)