advent-of-code/2020/day1/day1.js
2020-12-05 01:43:42 +01:00

25 lines
745 B
JavaScript
Executable File

#!/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]);
}
}
}
}
});