JSPM

greedy-number-partitioning

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q51101F
  • License MIT

Greedy number partitioning algorithm

Package Exports

  • greedy-number-partitioning

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (greedy-number-partitioning) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

greedy-number-partitioning

This library implements the Greedy Number Partitioning algorithm.

This algorithm solves the problem of Multiway Number Partitioning, i.e. partitioning a multiset of numbers into a fixed number of subsets, such that the sums of the subsets are as similar as possible.

The algorithm doesn't guarantee to obtain optimal solution, but guaranteed approximation of the optimal solution in polynomial time.

Installation

Install using npm:

$ npm install greedy-number-partitioning

Usage

const greedyPartitioning = require('greedy-number-partitioning');

const arr = [6, 7, 16, 10, 15, 3, 11, 4, 12, 20, 5, 13, 19];

const numberOfSubsets = 3;

const output = greedyPartitioning(arr, numberOfSubsets);
// returns [
//  [19, 13, 7, 6, 3],    sum 48
//  [16, 15, 11, 4],      sum 46
//  [20, 12, 10, 5]       sum 47
// ]

Licence

MIT