Skip to content

Instantly share code, notes, and snippets.

@freddiefujiwara
Created December 8, 2011 23:56
Show Gist options
  • Save freddiefujiwara/1449329 to your computer and use it in GitHub Desktop.
Save freddiefujiwara/1449329 to your computer and use it in GitHub Desktop.
sum problem
var solve = function(k,arr){
var sums = {};
var sum = function(a){
var s = 0;
for(var j = 0 ; j < a.length ; j++){
s += a[j];
}
return s;
};
length = arr.length;
for(var i = 0 ; i < length ; i++){
sums[sum(arr)] = true;
arr.shift();
}
console.log(true == sums[k] ? k+"? YES" : k+"? NO");
};
solve(13,[1,2,4,7]);
solve(15,[1,2,4,7]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment