Skip to content

Instantly share code, notes, and snippets.

@sebbekarlsson
Created December 2, 2020 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebbekarlsson/c5ff49553bfa70e99ddeb7721e3ad4e1 to your computer and use it in GitHub Desktop.
Save sebbekarlsson/c5ff49553bfa70e99ddeb7721e3ad4e1 to your computer and use it in GitHub Desktop.
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