Skip to content

computational-combinatorics/set-partition

Repository files navigation

The Zahlen symbol
User:Watchduck / CC BY 3.0

Set partition algorithms for JavaScript. See docs.

🏗️ Caveat emptor! This is work in progress. Code may be working. Documentation may be present. Coherence may be. Maybe.

⚠️ 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

License Version Tests Dependencies GitHub issues Downloads

Code issues Code maintainability Code coverage (cov) Code technical debt Documentation Package size