@combinatorics/set-partition
v2.0.0
Published
Set partition algorithms for JavaScript
Downloads
2
Readme
:bento: @combinatorics/set-partition
Set partition algorithms for JavaScript. See docs.
:building_construction: Caveat emptor! This is work in progress. Code may be working. Documentation may be present. Coherence may be. Maybe.
:warning: The code requires
regeneratorRuntime
to be defined, for instance by importing regenerator-runtime/runtime.
import {
enumerate,
count,
_count,
sequence,
_sequence,
isPartition
} from '@combinatorics/set-partition';
import {range} from '@iterable-iterator/range';
import {map} from '@iterable-iterator/map';
enumerate(range(0)); // []
enumerate(range(1)); // [[0]]
enumerate(range(2)); // [[0], [1]] [[0, 1]]
count(0); // 1n
count(1); // 1n
count(2); // 2n
count(3); // 5n
count(4); // 15n
count(5); // 52n
count(6); // 203n
count(26); // 49631246523618756274n
_count(1,6); // 203
_count(1,26); // ???
sequence(); // 1n 1n 2n 3n 5n 15n 52n 203n ...
_sequence(1); // 1 1 2 3 5 15 52 203 ...
isPartition(range(5), [range(5)]); // true
isPartition(range(5), map(x => [x], range(5))); // true
isPartition(range(5), map(x => (function* () {yield x;})(), range(5))); // true
isPartition(range(5), [[0], [1], [2], [3], [4]]); // true
isPartition(range(5), [[0, 1], [2], [3], [4]]); // true
isPartition(range(5), [[2, 1], [3], [0, 4]]); // true
isPartition(range(5), [[], [0], [1], [2], [3], [4]]); // false
isPartition(range(5), [[0], [0], [1], [2], [3], [4]]); // false
isPartition(range(5), [[5], [0], [1], [2], [3], [4]]); // false