Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/reity/summations-js
Library to enumerate all natural number lists with a target sum.
https://github.com/reity/summations-js
combinations combinatorics enumeration exhaustive-search javascript-lib javascript-library mathematics
Last synced: 29 days ago
JSON representation
Library to enumerate all natural number lists with a target sum.
- Host: GitHub
- URL: https://github.com/reity/summations-js
- Owner: reity
- License: mit
- Created: 2019-12-05T04:03:34.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-12-06T04:59:34.000Z (about 5 years ago)
- Last Synced: 2024-02-23T00:22:51.947Z (10 months ago)
- Topics: combinations, combinatorics, enumeration, exhaustive-search, javascript-lib, javascript-library, mathematics
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/summations
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# summations-js
Library to enumerate all natural number lists with a target sum.[![npm version](https://badge.fury.io/js/summations.svg)](https://badge.fury.io/js/summations)
## Package Installation and Usage
The package is available on npm:
```shell
npm install summations
```
The library can be imported in the usual ways:
```javascript
var summations = require('summations');
```
The library also supports standalone usage in browsers:
```html```
## Examples
It is possible to enumerate all possible lists of natural numbers of a given length that add up to a target sum.
```javascript
var results = summations.sumLen(2, 3);
```
Given the object above, we can query it for each value
```javascript
> 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](https://mochajs.org/):
```javascript
npm test
```