diff options
Diffstat (limited to 'day10/day10-1.js')
-rw-r--r-- | day10/day10-1.js | 19 |
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) + |