-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathcombinatorics.d.ts
185 lines (185 loc) · 4.77 KB
/
combinatorics.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/**
* combinatorics.js
*
* Licensed under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
*
* @author: Dan Kogai <[email protected]>
*
* References:
* @link: http://www.ruby-doc.org/core-2.0/Array.html#method-i-combination
* @link: http://www.ruby-doc.org/core-2.0/Array.html#method-i-permutation
* @link: http://en.wikipedia.org/wiki/Factorial_number_system
* @link: https://en.wikipedia.org/wiki/Combinatorial_number_system
*/
export declare const version = "2.1.2";
/**
* BigInt Workaround
*
* https://github.com/streamich/memfs/issues/275
*/
type anyint = number | bigint;
/**
* Optional<T> will not be official so
* @link: https://github.com/microsoft/TypeScript/issues/19944
*/
type Optional<T> = T | undefined;
/**
* calculates `P(n, k)`.
*
* @link https://en.wikipedia.org/wiki/Permutation
*/
export declare function permutation(n: anyint, k: anyint): bigint;
/**
* calculates `C(n, k)`.
*
* @link https://en.wikipedia.org/wiki/Combination
*/
export declare function combination(n: anyint, k: anyint): bigint;
/**
* calculates `n!` === `P(n, n)`.
*
* @link https://en.wikipedia.org/wiki/Factorial
*/
export declare function factorial(n: anyint): bigint;
/**
* returns the factoradic representation of `n`, least significant order.
*
* @link https://en.wikipedia.org/wiki/Factorial_number_system
* @param {number} l the number of digits
*/
export declare function factoradic(n: anyint, l?: number): number[];
/**
* `combinadic(n, k)` returns a function
* that takes `m` as an argument and
* returns the combinadics representation of `m` for `n C k`.
*
* @link https://en.wikipedia.org/wiki/Combinatorial_number_system
*/
export declare function combinadic(n: anyint, k: anyint): (m: anyint) => number[];
/**
* returns random integer `n` where `min` <= `n` < `max`:
*
* if the argument is `BigInt` the result is also `BigInt`.
*
* @param {anyint} min
* @param {anyint} max
*/
export declare function randomInteger(min?: anyint, max?: anyint): anyint;
/**
* Base Class of `js-combinatorics`
*/
declare class _CBase<T, U> {
/**
* does `new`
* @param args
*/
static of(...args: any[]): any;
/**
* Same as `of` but takes a single array `arg`
*
* cf. https://stackoverflow.com/questions/1606797/use-of-apply-with-new-operator-is-this-possible
*/
static from(arg: any): any;
/**
* Common iterator
*/
[Symbol.iterator](): Generator<U[], void, unknown>;
/**
* returns `[...this]`.
*/
toArray(): U[][];
/**
* @deprecated
* tells wether you need `BigInt` to access all elements.
*/
get isBig(): boolean;
/**
* @deprecated
* tells wether it is safe to work on this instance.
*
* * always `true` unless your platform does not support `BigInt`.
* * if not, `true` iff `.isBig` is `false`.
*/
get isSafe(): boolean;
/**
* check n for nth
*/
_check(n: anyint): anyint;
/**
* get the `n`th element of the iterator.
* negative `n` goes backwards
* like `Array.prototype.at()`
* @link: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at
*/
at(n: anyint): Optional<U[]>;
/**
* an alias of `at`
*/
nth(n: anyint): Optional<U[]>;
/**
* the seed iterable
*/
seed: T[];
/**
* the size (# of elements) of each element.
*/
size: number;
/**
* the number of elements
*/
length: bigint;
/**
* pick random element
*/
sample(): Optional<U[]>;
/**
* an infinite steam of random elements
*/
samples(): Generator<U[], never, unknown>;
}
/**
* Permutation
*/
export declare class Permutation<T> extends _CBase<T, T> {
constructor(seed: Iterable<T>, size?: number);
at(n: anyint): Optional<T[]>;
}
/**
* Combination
*/
export declare class Combination<T> extends _CBase<T, T> {
comb: (anyint: any) => number[];
constructor(seed: Iterable<T>, size?: number);
/**
* returns an iterator which is more efficient
* than the default iterator that uses .nth
*
* @link https://en.wikipedia.org/wiki/Combinatorial_number_system#Applications
*/
bitwiseIterator(): Generator<T[], void, unknown>;
at(n: anyint): Optional<T[]>;
}
/**
* Base N
*/
export declare class BaseN<T> extends _CBase<T, T> {
base: number;
constructor(seed: Iterable<T>, size?: number);
at(n: anyint): Optional<T[]>;
}
/**
* Power Set
*/
export declare class PowerSet<T> extends _CBase<T, T> {
constructor(seed: Iterable<T>);
at(n: anyint): Optional<T[]>;
}
/**
* Cartesian Product
*/
export declare class CartesianProduct<T> extends _CBase<T[], T> {
constructor(...args: Iterable<T>[]);
at(n: anyint): Optional<T[]>;
}
export {};