Skip to content

Instantly share code, notes, and snippets.

@konijn
Created December 3, 2013 13:56
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 konijn/7769510 to your computer and use it in GitHub Desktop.
Save konijn/7769510 to your computer and use it in GitHub Desktop.
function sortfunction(a, b)
{
return (a - b) //causes an array to be sorted numerically and ascending
}
function canWeDoIt( target , a )
{
if( a.length == 1 )
return (a[0] == target);
if( a[0] == target )
return true;
var i = a.shift();
if( i > target )
return canWeDoIt( target , a.slice(0) );
else
return canWeDoIt( target , a.slice(0) ) || canWeDoIt( target - i , a.slice(0) );
}
function ArrayAdditionI(arr)
{
arr = arr.sort(sortfunction);
var target = arr.pop()
//return target;
return canWeDoIt( target , arr )
}
// keep this function call here
// to see how to enter arguments in JavaScript scroll down
ArrayAdditionI(readline());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment