@thi.ng/math 5.3.18 → 5.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -1
- package/README.md +2 -2
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +11 -8
- package/permutations.d.ts +42 -0
- package/permutations.js +48 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**:
|
|
3
|
+
- **Last updated**: 2023-02-05T14:42:22Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
## [5.4.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/math@5.4.0) (2023-01-10)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- add factorial. permutation/combination fns ([965af0d](https://github.com/thi-ng/umbrella/commit/965af0d))
|
|
17
|
+
|
|
12
18
|
## [5.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/math@5.3.0) (2022-03-11)
|
|
13
19
|
|
|
14
20
|
#### 🚀 Features
|
package/README.md
CHANGED
|
@@ -66,7 +66,7 @@ For Node.js REPL:
|
|
|
66
66
|
const math = await import("@thi.ng/math");
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
-
Package sizes (brotli'd, pre-treeshake): ESM:
|
|
69
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 4.03 KB
|
|
70
70
|
|
|
71
71
|
## Dependencies
|
|
72
72
|
|
|
@@ -116,4 +116,4 @@ If this project contributes to an academic publication, please cite it as:
|
|
|
116
116
|
|
|
117
117
|
## License
|
|
118
118
|
|
|
119
|
-
© 2013 -
|
|
119
|
+
© 2013 - 2023 Karsten Schmidt // Apache License 2.0
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/math",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.4.1",
|
|
4
4
|
"description": "Assorted common math functions & utilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -37,15 +37,15 @@
|
|
|
37
37
|
"test": "testament test"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@thi.ng/api": "^8.
|
|
40
|
+
"@thi.ng/api": "^8.7.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@microsoft/api-extractor": "^7.
|
|
44
|
-
"@thi.ng/testament": "^0.3.
|
|
45
|
-
"rimraf": "^
|
|
43
|
+
"@microsoft/api-extractor": "^7.34.2",
|
|
44
|
+
"@thi.ng/testament": "^0.3.10",
|
|
45
|
+
"rimraf": "^4.1.2",
|
|
46
46
|
"tools": "^0.0.1",
|
|
47
|
-
"typedoc": "^0.23.
|
|
48
|
-
"typescript": "^4.9.
|
|
47
|
+
"typedoc": "^0.23.24",
|
|
48
|
+
"typescript": "^4.9.5"
|
|
49
49
|
},
|
|
50
50
|
"keywords": [
|
|
51
51
|
"animation",
|
|
@@ -113,6 +113,9 @@
|
|
|
113
113
|
"./mix": {
|
|
114
114
|
"default": "./mix.js"
|
|
115
115
|
},
|
|
116
|
+
"./permutations": {
|
|
117
|
+
"default": "./permutations.js"
|
|
118
|
+
},
|
|
116
119
|
"./prec": {
|
|
117
120
|
"default": "./prec.js"
|
|
118
121
|
},
|
|
@@ -135,5 +138,5 @@
|
|
|
135
138
|
"thi.ng": {
|
|
136
139
|
"year": 2013
|
|
137
140
|
},
|
|
138
|
-
"gitHead": "
|
|
141
|
+
"gitHead": "50ba9c87676fac60c46d2bc0e4d2c7711a374a68\n"
|
|
139
142
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes factorial for `n`. Throws an error if `n < 0`.
|
|
3
|
+
*
|
|
4
|
+
* @param n
|
|
5
|
+
*/
|
|
6
|
+
export declare const factorial: (n: number) => number;
|
|
7
|
+
/**
|
|
8
|
+
* Computes `n ** k`
|
|
9
|
+
*
|
|
10
|
+
* @param n number of choices
|
|
11
|
+
* @param k number of selected
|
|
12
|
+
*/
|
|
13
|
+
export declare const permutationsWithRep: (n: number, k: number) => number;
|
|
14
|
+
/**
|
|
15
|
+
* Computes `n! / (n - k)!`
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* Reference:
|
|
19
|
+
* https://en.wikipedia.org/wiki/Permutation#k-permutations_of_n
|
|
20
|
+
*
|
|
21
|
+
* @param n number of choices
|
|
22
|
+
* @param k number of selected
|
|
23
|
+
*/
|
|
24
|
+
export declare const permutationsWithoutRep: (n: number, k: number) => number;
|
|
25
|
+
/**
|
|
26
|
+
* Computes `(n + k - 1)! / (k! * (n - 1)!)`
|
|
27
|
+
*
|
|
28
|
+
* @param n number of choices
|
|
29
|
+
* @param k number of selected
|
|
30
|
+
*/
|
|
31
|
+
export declare const combinationsWithRep: (n: number, k: number) => number;
|
|
32
|
+
/**
|
|
33
|
+
* Computes `n! / (k! * (n - k)!)`
|
|
34
|
+
*
|
|
35
|
+
* @remarks
|
|
36
|
+
* https://en.wikipedia.org/wiki/Combination#Number_of_k-combinations
|
|
37
|
+
*
|
|
38
|
+
* @param n number of choices
|
|
39
|
+
* @param k number of selected
|
|
40
|
+
*/
|
|
41
|
+
export declare const combinationsWithoutRep: (n: number, k: number) => number;
|
|
42
|
+
//# sourceMappingURL=permutations.d.ts.map
|
package/permutations.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes factorial for `n`. Throws an error if `n < 0`.
|
|
3
|
+
*
|
|
4
|
+
* @param n
|
|
5
|
+
*/
|
|
6
|
+
export const factorial = (n) => {
|
|
7
|
+
if (n < 0)
|
|
8
|
+
throw new Error(`illegal argument: ${n}`);
|
|
9
|
+
let res = 1;
|
|
10
|
+
for (let i = 1; i <= n; i++)
|
|
11
|
+
res *= i;
|
|
12
|
+
return res;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Computes `n ** k`
|
|
16
|
+
*
|
|
17
|
+
* @param n number of choices
|
|
18
|
+
* @param k number of selected
|
|
19
|
+
*/
|
|
20
|
+
export const permutationsWithRep = (n, k) => n ** k;
|
|
21
|
+
/**
|
|
22
|
+
* Computes `n! / (n - k)!`
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* Reference:
|
|
26
|
+
* https://en.wikipedia.org/wiki/Permutation#k-permutations_of_n
|
|
27
|
+
*
|
|
28
|
+
* @param n number of choices
|
|
29
|
+
* @param k number of selected
|
|
30
|
+
*/
|
|
31
|
+
export const permutationsWithoutRep = (n, k) => factorial(n) / factorial(n - k);
|
|
32
|
+
/**
|
|
33
|
+
* Computes `(n + k - 1)! / (k! * (n - 1)!)`
|
|
34
|
+
*
|
|
35
|
+
* @param n number of choices
|
|
36
|
+
* @param k number of selected
|
|
37
|
+
*/
|
|
38
|
+
export const combinationsWithRep = (n, k) => factorial(n + k - 1) / (factorial(k) * factorial(n - 1));
|
|
39
|
+
/**
|
|
40
|
+
* Computes `n! / (k! * (n - k)!)`
|
|
41
|
+
*
|
|
42
|
+
* @remarks
|
|
43
|
+
* https://en.wikipedia.org/wiki/Combination#Number_of_k-combinations
|
|
44
|
+
*
|
|
45
|
+
* @param n number of choices
|
|
46
|
+
* @param k number of selected
|
|
47
|
+
*/
|
|
48
|
+
export const combinationsWithoutRep = (n, k) => factorial(n) / (factorial(k) * factorial(n - k));
|