Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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