Skip to content

Instantly share code, notes, and snippets.

@jazzyjackson
Created December 1, 2020 08:07
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 jazzyjackson/a916b8c4fe4336cb27c8c39deb8c2699 to your computer and use it in GitHub Desktop.
Save jazzyjackson/a916b8c4fe4336cb27c8c39deb8c2699 to your computer and use it in GitHub Desktop.
// 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