25 lines
745 B
JavaScript
25 lines
745 B
JavaScript
|
#!/bin/node
|
||
|
|
||
|
const fs = require('fs');
|
||
|
|
||
|
fs.readFile('input.txt', (err, data) => {
|
||
|
const numbers = data.toString().split('\n').map(n => parseInt(n));
|
||
|
for (let i = 0; i < numbers.length; i++) {
|
||
|
for (let j = i + 1; j < numbers.length; j++) {
|
||
|
if (numbers[i] + numbers[j] === 2020) {
|
||
|
console.log(numbers[i] * numbers[j]);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
for (let i = 0; i < numbers.length; i++) {
|
||
|
for (let j = i + 1; j < numbers.length; j++) {
|
||
|
for (let k = j + 1; k < numbers.length; k++) {
|
||
|
if (numbers[i] + numbers[j] + numbers[k] === 2020) {
|
||
|
console.log(numbers[i] * numbers[j] * numbers[k]);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
});
|