summations
v0.0.5
Published
Library to enumerate all natural number lists with a target sum.
Downloads
11,596
Readme
summations-js
Library to enumerate all natural number lists with a target sum.
Package Installation and Usage
The package is available on npm:
npm install summations
The library can be imported in the usual ways:
var summations = require('summations');
The library also supports standalone usage in browsers:
<script src="https://reity.org/summations-js/lib/summations.js"></script>
Examples
It is possible to enumerate all possible lists of natural numbers of a given length that add up to a target sum.
var results = summations.sumLen(2, 3);
Given the object above, we can query it for each value
> results
[
[1, 1, 0],
[0, 1, 1],
[1, 0, 1],
[2, 0, 0],
[0, 2, 0],
[0, 0, 2],
]
Testing
Unit tests are included in test/test.js
. They can be run using Mocha:
npm test