Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
fs = require("fs");
const N = 2020;
const FILENAME = "input.txt";
const ENCODING = "utf8";
fs.readFile(FILENAME, ENCODING, (_, data) =>
main(data.split("\n").map((line) => parseInt(line, 10)))
);
const main = (numbers) =>
console.log(
((numbers, b) => (numbers.length ? numbers[0] : b))(
numbers.flatMap((x) =>
numbers.flatMap((y) => (x + y === N ? [x * y] : []))
)
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment