Skip to content

Instantly share code, notes, and snippets.

@Slackwise
Created December 2, 2020 15:32
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 Slackwise/2a36bdc73925949bf11a4f5d878b94f2 to your computer and use it in GitHub Desktop.
Save Slackwise/2a36bdc73925949bf11a4f5d878b94f2 to your computer and use it in GitHub Desktop.
Run this in the Chrome console (Ctrl-Shift-J) on the input file.
const numbers = document.body.textContent.trim().split('\n').map(Number);
const set = new Set(numbers);
const goalSum = 2020;
const difference = n => goalSum - n;
const subtrahend = numbers.find(n => set.has(difference(n)));
const minuend = difference(subtrahend);
const product = subtrahend * minuend;
console.log(product);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment