diff options
author | 2020-12-10 20:48:06 +0100 | |
---|---|---|
committer | 2020-12-10 20:48:06 +0100 | |
commit | d0588d654684a5a6d5dfec3b983cb4f41d057ca6 (patch) | |
tree | 4c05811f25de85c1ca0f7fe3d314addd8d2d136b /day9/day9-1.js | |
parent | b50c9c40ae474cd0e4eb543504e47dc6dbea31e9 (diff) | |
download | advent_of_code_2020-d0588d654684a5a6d5dfec3b983cb4f41d057ca6.tar.gz advent_of_code_2020-d0588d654684a5a6d5dfec3b983cb4f41d057ca6.tar.bz2 advent_of_code_2020-d0588d654684a5a6d5dfec3b983cb4f41d057ca6.zip |
day9
Diffstat (limited to 'day9/day9-1.js')
-rw-r--r-- | day9/day9-1.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/day9/day9-1.js b/day9/day9-1.js new file mode 100644 index 0000000..99ed680 --- /dev/null +++ b/day9/day9-1.js @@ -0,0 +1,24 @@ +const data = require('./data') +const test = (d, i, nr) => { + if (i > nr) { + let sums = [] + for (let a = i - nr - 1; a < i; a++) { + for (let b = i - nr - 1; b < i; b++) { + if (a !== b) { + sums.push(data[a]+data[b]) + } + } + } + return sums.indexOf(data[i]) < 0 + } else { + return false + } +} + +const findNr = (nr) => ( + data.find((d, i) => { + return test(d, i, nr) + }) +) + +console.log(findNr(25)) |