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