Skip to content
{{ message }}

# haensl / subset-sum

Node.js library to find solutions to the coin changing problem.

Switch branches/tags
Could not load branches
Nothing to show

## Files

Failed to load latest commit information.
Type
Name
Commit time

# Subset sum Node.js module to compute solutions to the Coin changing problem, i.e. find combinations of integers from a given set of available integers that sum up to a desired result.

## Quick start

1. Install the library

via `npm`

`npm i -S @haensl/subset-sum`

via `yarn`

`yarn add @haensl/subset-sum`
1. Use the library in your code

in CommonJS (e.g. Node.js)

```const sumService = require('@haensl/subset-sum');

const numbers = [1, 4, 2, 5, 1, 3];
const target = 6;
const solver = sumService.subsetSum(numbers, target);

for (let solution of solver) {
console.log(solution);
}```

in ESM (e.g. Browser)

```import sumService from '@haensl/subset-sum';

const numbers = [1, 4, 2, 5, 1, 3];
const target = 6;
const solver = sumService.subsetSum(numbers, target);

for (let solution of solver) {
console.log(solution);
}```

## API

`subsetSum(numbers, target) => Generator`

Returns a generator that yields arrays of integers from `numbers` that add up to `target`.

`uniqueSolutions(solutions) => Array`

Filters `solutions` for unique solutions.

`isSameSolution(solutionA, solutionB) => boolean`

Compares to solutions and determines if they are equal, i.e. contain the same integers. E.g. `[1, 1, 3, 1]` and `[1, 3, 1, 1]` are considered equal.

## About

Node.js library to find solutions to the coin changing problem.

v3.0.0 Latest
Aug 23, 2020

## Packages 0

No packages published

•
•