This Repo provides a naive solver for the Subset Sum Problem.
The solution is based on the following steps:
- generate the power set of the given set
- for every element in the power set calculate the sum, if any of the elements sums to zero, then that element is a solution to this problem
Using runkit. Simply click here and copy/paste this code:
const naiveSubsetSum = require("naive-subset-sum");
const input = [1,-3,2,11];
console.log(naiveSubsetSum.subsetSum(input));
You will need node JS installed.
- Install the library:
npm install naive-subset-sum
- Run the below command:
node node_modules/naive-subset-sum/index.js
> .ssum 1,2,-7,2,3
{ res: true, subset: [ 3, 2, -7, 2 ] }
You will need node JS installed.
You can clone this repo and start by simply running:
node index.js
> .ssum 1,2,-7,2,3
{ res: true, subset: [ 3, 2, -7, 2 ] }