Created
December 1, 2020 08:07
-
-
Save jazzyjackson/a916b8c4fe4336cb27c8c39deb8c2699 to your computer and use it in GitHub Desktop.
This file contains 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
// complement sum | |
// ask "what is the complement for x number" and then "Do I have it?" | |
let goal = 2020 | |
let marbles = new Set([1721, 979, 366, 299, 675, 1456]) | |
let complement | |
main: | |
for(var marble of marbles){ | |
complement = goal - marble | |
if(marbles.has(complement)){ | |
console.log(`${marble} + ${complement} = ${goal}`) | |
// 299 + 1721 = 2020 | |
console.log(`${marble} * ${complement} = ${marble * complement}`) | |
// 299 * 1721 = 514579 | |
break main | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment