summaryrefslogtreecommitdiffstats
path: root/day10/day10-1.js
diff options
context:
space:
mode:
authorGravatar Piotr Russ <piotr.russ@betvictor.com> 2020-12-10 20:54:28 +0100
committerGravatar Piotr Russ <piotr.russ@betvictor.com> 2020-12-10 20:54:28 +0100
commit468e261bccd8fc44ee6ffd3e7fda1c3659a7ab1d (patch)
treedeb1871886c5f24ca58529c35340ff896d0dcecc /day10/day10-1.js
parentd0588d654684a5a6d5dfec3b983cb4f41d057ca6 (diff)
downloadadvent_of_code_2020-468e261bccd8fc44ee6ffd3e7fda1c3659a7ab1d.tar.gz
advent_of_code_2020-468e261bccd8fc44ee6ffd3e7fda1c3659a7ab1d.tar.bz2
advent_of_code_2020-468e261bccd8fc44ee6ffd3e7fda1c3659a7ab1d.zip
day10
Diffstat (limited to 'day10/day10-1.js')
-rw-r--r--day10/day10-1.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/day10/day10-1.js b/day10/day10-1.js
new file mode 100644
index 0000000..36363cc
--- /dev/null
+++ b/day10/day10-1.js
@@ -0,0 +1,19 @@
+const data = require('./data')
+let jolts = 0, diff1 = 0, diff3 = 1
+
+const next = () => {
+ const possible = data.filter(a => [jolts+1, jolts+2, jolts+3].indexOf(a) > -1)
+ return possible.length > 0 && Math.min.apply(Math, possible)
+}
+
+while (next()) {
+ if ((next() - jolts) === 1) {
+ diff1 += 1
+ } else if ((next() - jolts) === 3) {
+ diff3 += 1
+ }
+ jolts = next()
+}
+
+console.log(diff1*diff3)
+