-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReport.js
38 lines (34 loc) · 831 Bytes
/
Report.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// read data.txt
// save data to array
// parse to int
// find x + y = 2020
var fs = require("fs");
var content = fs
.readFileSync("report-input.txt", "utf-8", (err) => {
if (err) {
console.log(err);
}
})
.split("\n");
for (let i in content) {
content[i];
}
console.log("File read, ex num:", content[0]);
let array = content.map((item) => parseInt(item, 10)); // could use Number() also
let sum = 2020;
const bruteForce = (array, sum) => {
let result = [];
for (let x in array) {
for (let y in array) {
for (let z in array) {
if (array[x] + array[y] + array[z] === sum) {
result.push([array[x], array[y], array[z]]);
console.log([array[x] * array[y] * array[z]]);
}
}
}
}
console.log("result: ", result);
return;
};
bruteForce(array, sum);