You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
612 B
JavaScript
26 lines
612 B
JavaScript
4 years ago
|
const fs = require("fs");
|
||
|
|
||
|
const filename = "input";
|
||
|
|
||
|
async function main() {
|
||
|
const file = await fs.promises.readFile(filename, "utf-8");
|
||
|
const expenses = file.split("\n").map((num) => parseInt(num));
|
||
|
console.log(expenses);
|
||
|
|
||
|
for (let i = 0; i < expenses.length; i++) {
|
||
|
const a = expenses[i];
|
||
|
const counterpart = 2020 - a;
|
||
|
for (let j = 0; j < expenses.length; j++) {
|
||
|
const b = expenses[j];
|
||
|
for (let k = 0; k < expenses.length; k++) {
|
||
|
const c = expenses[k];
|
||
|
if (a + b + c === 2020) {
|
||
|
console.log(a, b, c, a * b * c);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
main();
|