summations

0.0.5 • Public • Published

summations-js

Library to enumerate all natural number lists with a target sum.

npm version

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

Package Sidebar

Install

npm i summations

Weekly Downloads

5

Version

0.0.5

License

MIT

Unpacked Size

4.75 kB

Total Files

5

Last publish

Collaborators

  • lapets