29 lines
777 B
JavaScript
29 lines
777 B
JavaScript
const { Glib } = require('../../lib');
|
|
|
|
module.exports = {
|
|
'1': (input) => {
|
|
input = Glib.fromLines(input).toInts().array;
|
|
for (let i = 0; i < input.length; i++) {
|
|
for (let j = i; j < input.length; j++) {
|
|
if (input[i] + input[j] === 2020n) {
|
|
return input[i] * input[j];
|
|
}
|
|
}
|
|
}
|
|
throw new Error('no solution');
|
|
},
|
|
'2': (input) => {
|
|
input = Glib.fromLines(input).toInts().array;
|
|
for (let i = 0; i < input.length; i++) {
|
|
for (let j = i + 1; j < input.length; j++) {
|
|
for (let k = j + 1; k < input.length; k++) {
|
|
if (input[i] + input[j] + input[k] === 2020n) {
|
|
return input[i] * input[j] * input[k];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
throw new Error('no solution');
|
|
},
|
|
};
|