blob: 36363cc5ac7fe2a88c7ea7563facfb20705f570d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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)
|