From 468e261bccd8fc44ee6ffd3e7fda1c3659a7ab1d Mon Sep 17 00:00:00 2001 From: Piotr Russ Date: Thu, 10 Dec 2020 20:54:28 +0100 Subject: day10 --- day10/day10-1.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 day10/day10-1.js (limited to 'day10/day10-1.js') 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) + -- cgit v1.2.3