summaryrefslogtreecommitdiffstats
path: root/day9/day9-1.js
diff options
context:
space:
mode:
Diffstat (limited to 'day9/day9-1.js')
-rw-r--r--day9/day9-1.js24
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))