Created
December 2, 2020 15:32
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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