ziko 0.54.5 → 0.55.0
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/dist/ziko.cjs +298 -444
- package/dist/ziko.js +297 -626
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +297 -618
- package/package.json +1 -1
- package/src/math/--discret/index.js +12 -0
- package/src/math/complex/index.js +18 -12
- package/src/math/functions/conversions/index.js +61 -0
- package/src/math/functions/index.js +1 -1
- package/src/math/functions/signal/index.js +1 -1
- package/src/math/functions/stats/index.js +14 -2
- package/src/math/functions/utils/index.js +0 -58
- package/src/math/index.js +2 -2
- package/src/math/matrix/index.js +52 -35
- package/src/math/random/index.js +111 -155
- package/src/math/utils/conversions.js +17 -17
- package/src/math/utils/index.js +10 -10
- package/types/math/complex/index.d.ts +5 -5
- package/src/math/discret/Combinaison/index.js +0 -34
- package/src/math/discret/Conversion/index.js +0 -86
- package/src/math/discret/Permutation/index.js +0 -31
- package/src/math/discret/index.js +0 -12
- package/src/math/statistics/functions/index.js +0 -100
- package/src/math/statistics/index.js +0 -16
- /package/src/math/{discret → --discret}/Set/index.js +0 -0
- /package/src/math/{discret → --discret}/Set/power-set.js +0 -0
- /package/src/math/{discret → --discret}/Set/sub-set.js +0 -0
- /package/src/math/functions/{nested → ufunc}/index.js +0 -0
package/src/math/random/index.js
CHANGED
|
@@ -1,169 +1,125 @@
|
|
|
1
|
+
import { base2base } from "../functions/conversions/index.js";
|
|
2
|
+
import { accum_sum } from "../functions/stats/index.js";
|
|
1
3
|
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class Random {
|
|
5
|
-
static float(a = 1, b) {
|
|
6
|
-
return b ? Math.random() * (b - a) + a : a * Math.random();
|
|
7
|
-
}
|
|
8
|
-
static int(a, b) {
|
|
4
|
+
export class Random {
|
|
5
|
+
static int(a, b){
|
|
9
6
|
return Math.floor(this.float(a, b));
|
|
10
7
|
}
|
|
11
|
-
static
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
static bool(){
|
|
17
|
-
return [false,true][Math.floor(Math.random()*2)];
|
|
18
|
-
}
|
|
19
|
-
static string(length,upperCase){
|
|
20
|
-
return length instanceof Array?
|
|
21
|
-
new Array(this.int(...length)).fill(0).map(() => this.char(upperCase)).join(""):
|
|
22
|
-
new Array(length).fill(0).map(() => this.char(upperCase)).join("");
|
|
8
|
+
static float(a, b){
|
|
9
|
+
return b !== undefined
|
|
10
|
+
? Math.random() * (b - a) + a
|
|
11
|
+
: Math.random() * a;
|
|
23
12
|
}
|
|
24
|
-
static bin()
|
|
13
|
+
static bin(){
|
|
25
14
|
return this.int(2);
|
|
26
15
|
}
|
|
27
|
-
static oct()
|
|
28
|
-
return this.int(8);
|
|
29
|
-
}
|
|
30
|
-
static dec() {
|
|
16
|
+
static oct(){
|
|
31
17
|
return this.int(8);
|
|
32
18
|
}
|
|
33
|
-
static
|
|
34
|
-
return this.int(
|
|
35
|
-
}
|
|
36
|
-
static choice(choices = [1, 2, 3], p = new Array(choices.length).fill(1 / choices.length)) {
|
|
37
|
-
let newchoice = new Array(100);
|
|
38
|
-
p=Utils.accum(...p).map(n=>n*100)
|
|
39
|
-
newchoice.fill(choices[0], 0, p[0]);
|
|
40
|
-
for (let i = 1; i < choices.length; i++) newchoice.fill(choices[i], p[i - 1], p[i]);
|
|
41
|
-
return newchoice[this.int(newchoice.length - 1)];
|
|
42
|
-
}
|
|
43
|
-
static shuffleArr(arr){
|
|
44
|
-
return arr.sort(()=>0.5-Math.random())
|
|
45
|
-
}
|
|
46
|
-
static floats(n, a, b) {
|
|
47
|
-
return new Array(n).fill(0).map(() => this.float(a, b));
|
|
48
|
-
}
|
|
49
|
-
static ints(n, a, b) {
|
|
50
|
-
return new Array(n).fill(0).map(() => this.int(a, b));
|
|
51
|
-
}
|
|
52
|
-
static bools(n){
|
|
53
|
-
return new Array(n).fill(0).map(() => this.bool());
|
|
19
|
+
static dec(){
|
|
20
|
+
return this.int(10);
|
|
54
21
|
}
|
|
55
|
-
static
|
|
56
|
-
return
|
|
22
|
+
static hex(){
|
|
23
|
+
return base2base(this.int(16), 10, 16);
|
|
57
24
|
}
|
|
58
|
-
static
|
|
59
|
-
|
|
25
|
+
static char(upperCase = false){
|
|
26
|
+
const i = upperCase
|
|
27
|
+
? this.int(65, 91)
|
|
28
|
+
: this.int(97, 123);
|
|
29
|
+
return String.fromCharCode(i);
|
|
60
30
|
}
|
|
61
|
-
static
|
|
62
|
-
return
|
|
63
|
-
}
|
|
64
|
-
static hexs(n) {
|
|
65
|
-
return new Array(n).fill(0).map(() => this.int(16));
|
|
66
|
-
}
|
|
67
|
-
static choices(n, choices, p) {
|
|
68
|
-
return new Array(n).fill(0).map(() => this.choice(choices, p));
|
|
69
|
-
}
|
|
70
|
-
static perm(...arr) {
|
|
71
|
-
// permutation
|
|
72
|
-
return arr.permS[this.int(arr.length)];
|
|
73
|
-
}
|
|
74
|
-
static color() {
|
|
75
|
-
return "#" + Base.dec2hex(this.float(16777216)).padStart(6,0);
|
|
76
|
-
}
|
|
77
|
-
static colors(n) {
|
|
78
|
-
return new Array(n).fill(null).map(()=>this.color());
|
|
31
|
+
static bool(){
|
|
32
|
+
return Boolean(this.int(2));
|
|
79
33
|
}
|
|
34
|
+
static get color(){
|
|
35
|
+
return {
|
|
36
|
+
hex : () =>
|
|
37
|
+
`#${this.int(0xffffff).toString(16).padStart(6, '0')}`,
|
|
80
38
|
|
|
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
|
-
// static matrixComplexInt(r,c,a,b){
|
|
154
|
-
// return matrix(r,c,this.complexesInt(r*c,a,b))
|
|
155
|
-
// }
|
|
156
|
-
// static matrixComplexBin(r,c){
|
|
157
|
-
// return matrix(r,c,this.complexesBin(r*c))
|
|
158
|
-
// }
|
|
159
|
-
// static matrixComplexOct(r,c){
|
|
160
|
-
// return matrix(r,c,this.complexesBin(r*c))
|
|
161
|
-
// }
|
|
162
|
-
// static matrixComplexDec(r,c){
|
|
163
|
-
// return matrix(r,c,this.complexesBin(r*c))
|
|
164
|
-
// }
|
|
165
|
-
// static matrixComplexHex(r,c){
|
|
166
|
-
// return matrix(r,c,this.complexesBin(r*c))
|
|
167
|
-
// }
|
|
39
|
+
hexa : () => {
|
|
40
|
+
const [r,g,b,a] = Array.from(
|
|
41
|
+
{length:4},
|
|
42
|
+
() => this.int(0xff).toString(16).padStart(2,'0')
|
|
43
|
+
);
|
|
44
|
+
return `#${r}${g}${b}${a}`;
|
|
45
|
+
},
|
|
46
|
+
rgb : () => {
|
|
47
|
+
const [r,g,b] = Array.from({length:3}, () => this.int(0xff));
|
|
48
|
+
return `rgb(${r}, ${g}, ${b})`;
|
|
49
|
+
},
|
|
50
|
+
rgba : () => {
|
|
51
|
+
const [r,g,b] = Array.from({length:3}, () => this.int(0xff));
|
|
52
|
+
const a = Math.random().toFixed(2);
|
|
53
|
+
return `rgba(${r}, ${g}, ${b}, ${a})`;
|
|
54
|
+
},
|
|
55
|
+
hsl : () => {
|
|
56
|
+
const h = this.int(360);
|
|
57
|
+
const s = this.int(100);
|
|
58
|
+
const l = this.int(100);
|
|
59
|
+
return `hsl(${h}, ${s}%, ${l}%)`;
|
|
60
|
+
},
|
|
61
|
+
hsla : () => {
|
|
62
|
+
const h = this.int(360);
|
|
63
|
+
const s = this.int(100);
|
|
64
|
+
const l = this.int(100);
|
|
65
|
+
const a = Math.random().toFixed(2);
|
|
66
|
+
return `hsla(${h}, ${s}%, ${l}%, ${a})`;
|
|
67
|
+
},
|
|
68
|
+
gray : () => {
|
|
69
|
+
const g = this.int(0xff);
|
|
70
|
+
return `rgb(${g}, ${g}, ${g})`;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
static get sample(){
|
|
75
|
+
const R = this;
|
|
76
|
+
return {
|
|
77
|
+
int : (n,a,b) => Array.from({length:n}, () => R.int(a,b)),
|
|
78
|
+
float : (n,a,b) => Array.from({length:n}, () => R.float(a,b)),
|
|
79
|
+
char : (n,upper=false) => Array.from({length:n}, () => R.char(upper)),
|
|
80
|
+
bool : n => Array.from({length:n}, () => R.bool()),
|
|
81
|
+
bin : n => Array.from({length:n}, () => R.bin()),
|
|
82
|
+
oct : n => Array.from({length:n}, () => R.oct()),
|
|
83
|
+
dec : n => Array.from({length:n}, () => R.dec()),
|
|
84
|
+
hex : n => Array.from({length:n}, () => R.hex()),
|
|
85
|
+
get color(){
|
|
86
|
+
return {
|
|
87
|
+
hex : n => Array.from({length:n}, () => R.color.hex()),
|
|
88
|
+
hexa : n => Array.from({length:n}, () => R.color.hexa()),
|
|
89
|
+
rgb : n => Array.from({length:n}, () => R.color.rgb()),
|
|
90
|
+
rgba : n => Array.from({length:n}, () => R.color.rgba()),
|
|
91
|
+
hsl : n => Array.from({length:n}, () => R.color.hsl()),
|
|
92
|
+
hsla : n => Array.from({length:n}, () => R.color.hsla()),
|
|
93
|
+
gray : n => Array.from({length:n}, () => R.color.gray())
|
|
94
|
+
};
|
|
95
|
+
},
|
|
96
|
+
choice : (n, choices, p) =>
|
|
97
|
+
Array.from({length:n}, () => R.choice(choices, p))
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
static shuffle(arr){
|
|
101
|
+
return [...arr].sort(() => 0.5 - Math.random());
|
|
102
|
+
}
|
|
103
|
+
static choice(choices = [1,2,3], p = new Array(choices.length).fill(1 / choices.length)){
|
|
104
|
+
const acc = accum_sum(...p).map(v => v * 100);
|
|
105
|
+
const pool = new Array(100);
|
|
106
|
+
pool.fill(choices[0], 0, acc[0]);
|
|
107
|
+
for(let i=1;i<choices.length;i++)
|
|
108
|
+
pool.fill(choices[i], acc[i-1], acc[i]);
|
|
109
|
+
return pool[this.int(pool.length)];
|
|
110
|
+
}
|
|
168
111
|
}
|
|
169
|
-
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
globalThis.Random = Random
|
|
115
|
+
|
|
116
|
+
// // (upperCase) => upperCase ? : String.fromCharCode(rand_int(97,120))
|
|
117
|
+
// class Random {
|
|
118
|
+
// static string(length,upperCase){
|
|
119
|
+
// return length instanceof Array?
|
|
120
|
+
// new Array(this.int(...length)).fill(0).map(() => this.char(upperCase)).join(""):
|
|
121
|
+
// new Array(length).fill(0).map(() => this.char(upperCase)).join("");
|
|
122
|
+
// }
|
|
123
|
+
|
|
124
|
+
// }
|
|
125
|
+
// export{Random}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
/** @module Math */
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const deg2rad = (...deg) => mapfun(x => x * Math.PI / 180, ...deg);
|
|
1
|
+
// /** @module Math */
|
|
2
|
+
// /**
|
|
3
|
+
// * Converts degrees to radians.
|
|
4
|
+
// * @param {...number} deg - Degrees to convert.
|
|
5
|
+
// * @returns {number|number[]} Returns an array of radians corresponding to the input degrees.
|
|
6
|
+
// */
|
|
7
|
+
// const deg2rad = (...deg) => mapfun(x => x * Math.PI / 180, ...deg);
|
|
8
8
|
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const rad2deg = (...rad) => mapfun(x => x / Math.PI * 180, ...rad);
|
|
9
|
+
// /**
|
|
10
|
+
// * Converts radians to degrees.
|
|
11
|
+
// * @param {...number} rad - Radians to convert.
|
|
12
|
+
// * @returns {number|number[]} Returns an array of degrees corresponding to the input radians.
|
|
13
|
+
// */
|
|
14
|
+
// const rad2deg = (...rad) => mapfun(x => x / Math.PI * 180, ...rad);
|
|
15
15
|
|
|
16
|
-
export {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
16
|
+
// export {
|
|
17
|
+
// deg2rad,
|
|
18
|
+
// rad2deg
|
|
19
|
+
// }
|
package/src/math/utils/index.js
CHANGED
|
@@ -23,11 +23,11 @@ import {
|
|
|
23
23
|
// deg2rad,
|
|
24
24
|
// rad2deg
|
|
25
25
|
// } from "./conversions.js"
|
|
26
|
-
import{
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
} from "../statistics/index.js"
|
|
26
|
+
// import{
|
|
27
|
+
// sum,
|
|
28
|
+
// prod,
|
|
29
|
+
// accum
|
|
30
|
+
// } from "../statistics/index.js"
|
|
31
31
|
import{
|
|
32
32
|
inRange,
|
|
33
33
|
isApproximatlyEqual
|
|
@@ -56,9 +56,9 @@ const Utils={
|
|
|
56
56
|
logspace,
|
|
57
57
|
geomspace,
|
|
58
58
|
|
|
59
|
-
sum,
|
|
60
|
-
prod,
|
|
61
|
-
accum,
|
|
59
|
+
// sum,
|
|
60
|
+
// prod,
|
|
61
|
+
// accum,
|
|
62
62
|
|
|
63
63
|
cartesianProduct,
|
|
64
64
|
ppcm,
|
|
@@ -76,8 +76,8 @@ export {
|
|
|
76
76
|
zeros,
|
|
77
77
|
ones,
|
|
78
78
|
nums,
|
|
79
|
-
sum,
|
|
80
|
-
prod,
|
|
79
|
+
// sum,
|
|
80
|
+
// prod,
|
|
81
81
|
// add,
|
|
82
82
|
// mul,
|
|
83
83
|
// sub,
|
|
@@ -35,17 +35,17 @@ export declare class Complex {
|
|
|
35
35
|
mul(...z: (number | Complex)[]): this;
|
|
36
36
|
div(...z: (number | Complex)[]): this;
|
|
37
37
|
pow(n: number): this;
|
|
38
|
-
|
|
38
|
+
nthr(n?: number): Complex;
|
|
39
39
|
|
|
40
|
-
static
|
|
41
|
-
static
|
|
42
|
-
static
|
|
40
|
+
static zero(): Complex;
|
|
41
|
+
static twiddle(N : number, K : number): Complex;
|
|
42
|
+
static fromPolar(z: number, phi: number): Complex;
|
|
43
|
+
|
|
43
44
|
static add(c: Complex, ...z: (number | Complex)[]): Complex;
|
|
44
45
|
static sub(c: Complex, ...z: (number | Complex)[]): Complex;
|
|
45
46
|
static mul(c: Complex, ...z: (number | Complex)[]): Complex;
|
|
46
47
|
static div(c: Complex, ...z: (number | Complex)[]): Complex;
|
|
47
48
|
static pow(c: Complex, n: number): Complex;
|
|
48
|
-
static xpowZ(x: number): Complex;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
export declare function complex(a: number, b?: number): Complex;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
class Combinaison {
|
|
2
|
-
static withDiscount(comboOptions, comboLength) {
|
|
3
|
-
if (comboLength === 1) {
|
|
4
|
-
return comboOptions.map((comboOption) => [comboOption]);
|
|
5
|
-
}
|
|
6
|
-
const combos = [];
|
|
7
|
-
comboOptions.forEach((currentOption, optionIndex) => {
|
|
8
|
-
const smallerCombos = this.withDiscount(comboOptions.slice(optionIndex), comboLength - 1);
|
|
9
|
-
smallerCombos.forEach((smallerCombo) => {
|
|
10
|
-
combos.push([currentOption].concat(smallerCombo));
|
|
11
|
-
});
|
|
12
|
-
});
|
|
13
|
-
return combos;
|
|
14
|
-
}
|
|
15
|
-
static withoutDiscount(comboOptions, comboLength) {
|
|
16
|
-
if (comboLength === 1) {
|
|
17
|
-
return comboOptions.map((comboOption) => [comboOption]);
|
|
18
|
-
}
|
|
19
|
-
const combos = [];
|
|
20
|
-
comboOptions.forEach((currentOption, optionIndex) => {
|
|
21
|
-
const smallerCombos = this.withoutDiscount(comboOptions.slice(optionIndex + 1), comboLength - 1);
|
|
22
|
-
smallerCombos.forEach((smallerCombo) => {
|
|
23
|
-
combos.push([currentOption].concat(smallerCombo));
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
return combos;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
const combinaison=(comboOptions, comboLength, discount=false)=>Combinaison[discount?"withDiscount":"withoutDiscount"](comboOptions, comboLength)
|
|
31
|
-
export{
|
|
32
|
-
Combinaison,
|
|
33
|
-
combinaison
|
|
34
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { Complex } from "../../complex/index.js";
|
|
2
|
-
import { Matrix } from "../../matrix/index.js";
|
|
3
|
-
const Base={
|
|
4
|
-
_mode:Number,
|
|
5
|
-
_map:function(func,number,toBase){
|
|
6
|
-
if (number instanceof Matrix)
|
|
7
|
-
return new Matrix(
|
|
8
|
-
number.rows,
|
|
9
|
-
number.cols,
|
|
10
|
-
number.arr.flat(1).map(n=>func(n,toBase))
|
|
11
|
-
);
|
|
12
|
-
else if (number instanceof Complex) return new Complex(func(number.a,toBase),func(number.b,toBase));
|
|
13
|
-
else if (number instanceof Array) return number.map((n) =>func(n,toBase));
|
|
14
|
-
},
|
|
15
|
-
dec2base(dec,base){
|
|
16
|
-
base<=10?this._mode=Number:this._mode=String
|
|
17
|
-
//this._mode=String
|
|
18
|
-
if (typeof dec === "number") return this._mode((dec >>> 0).toString(base));
|
|
19
|
-
return this._map(this.dec2base,dec,base)
|
|
20
|
-
},
|
|
21
|
-
dec2bin(dec){
|
|
22
|
-
return this.dec2base(dec,2);
|
|
23
|
-
},
|
|
24
|
-
dec2oct(dec){
|
|
25
|
-
return this.dec2base(dec,8);
|
|
26
|
-
},
|
|
27
|
-
dec2hex(dec){
|
|
28
|
-
return this.dec2base(dec,16);
|
|
29
|
-
},
|
|
30
|
-
bin2base(bin, base) {
|
|
31
|
-
return this.dec2base(this.bin2dec(bin),base)
|
|
32
|
-
},
|
|
33
|
-
bin2dec(bin){
|
|
34
|
-
return this._mode("0b"+bin);
|
|
35
|
-
},
|
|
36
|
-
bin2oct(bin){
|
|
37
|
-
return this.bin2base(bin,8);
|
|
38
|
-
},
|
|
39
|
-
bin2hex(bin){
|
|
40
|
-
return this.bin2base(bin,16);
|
|
41
|
-
},
|
|
42
|
-
oct2dec(oct){
|
|
43
|
-
return this._mode("0o"+oct);
|
|
44
|
-
},
|
|
45
|
-
oct2bin(oct){
|
|
46
|
-
return this.dec2bin(this.oct2dec(oct))
|
|
47
|
-
},
|
|
48
|
-
oct2hex(oct){
|
|
49
|
-
return this.dec2hex(this.oct2dec(oct))
|
|
50
|
-
},
|
|
51
|
-
oct2base(oct, base) {
|
|
52
|
-
return this.dec2base(this.oct2dec(oct),base)
|
|
53
|
-
},
|
|
54
|
-
hex2dec(hex){
|
|
55
|
-
return this._mode("0x"+hex);
|
|
56
|
-
},
|
|
57
|
-
hex2bin(hex){
|
|
58
|
-
return this.dec2bin(this.hex2dec(hex))
|
|
59
|
-
},
|
|
60
|
-
hex2oct(hex){
|
|
61
|
-
return this.dec2oct(this.hex2dec(hex))
|
|
62
|
-
},
|
|
63
|
-
hex2base(hex, base) {
|
|
64
|
-
return this.dec2base(this.hex2dec(hex),base)
|
|
65
|
-
},
|
|
66
|
-
IEEE32toDec(Bin){
|
|
67
|
-
let IEEE32=Bin.split(" ").join("").padEnd(32,"0");
|
|
68
|
-
let s=IEEE32[0];
|
|
69
|
-
let e=2**(+("0b"+IEEE32.slice(1,9))-127)
|
|
70
|
-
let m=IEEE32.slice(9,32).split("").map(n=>+n)
|
|
71
|
-
let M=m.map((n,i)=>n*(2**(-i-1))).reduce((a,b)=>a+b,0);
|
|
72
|
-
let dec=(-1)**s*(1+M)*e;
|
|
73
|
-
return dec
|
|
74
|
-
},
|
|
75
|
-
IEEE64toDec(Bin){
|
|
76
|
-
let IEEE64=Bin.split(" ").join("").padEnd(64,"0");
|
|
77
|
-
let s=IEEE64[0];
|
|
78
|
-
let e=2**(+("0b"+IEEE64.slice(1,12))-1023)
|
|
79
|
-
let m=IEEE64.slice(13,64).split("").map(n=>+n)
|
|
80
|
-
let M=m.map((n,i)=>n*(2**(-i-1))).reduce((a,b)=>a+b,0);
|
|
81
|
-
let dec=(-1)**s*(1+M)*e;
|
|
82
|
-
return dec;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export{Base}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
class Permutation {
|
|
2
|
-
static withDiscount(arr, l = arr.length) {
|
|
3
|
-
if (l === 1) return arr.map((n) => [n]);
|
|
4
|
-
const permutations = [];
|
|
5
|
-
let smallerPermutations;
|
|
6
|
-
smallerPermutations = this.withDiscount(arr, l - 1);
|
|
7
|
-
arr.forEach((currentOption) => {
|
|
8
|
-
smallerPermutations.forEach((smallerPermutation) => {
|
|
9
|
-
permutations.push([currentOption].concat(smallerPermutation));
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
return permutations;
|
|
13
|
-
}
|
|
14
|
-
static withoutDiscount(arr) {
|
|
15
|
-
const l = arr.length;
|
|
16
|
-
if (l === 1) return arr.map((n) => [n]);
|
|
17
|
-
const permutations = [];
|
|
18
|
-
const smallerPermutations = this.withoutDiscount(arr.slice(1));
|
|
19
|
-
const firstOption = arr[0];
|
|
20
|
-
for (let i = 0; i < smallerPermutations.length; i++) {
|
|
21
|
-
const smallerPermutation = smallerPermutations[i];
|
|
22
|
-
for (let j = 0; j <= smallerPermutation.length; j++) {
|
|
23
|
-
const permutationPrefix = smallerPermutation.slice(0, j);
|
|
24
|
-
const permutationSuffix = smallerPermutation.slice(j);
|
|
25
|
-
permutations.push(permutationPrefix.concat([firstOption], permutationSuffix));
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return permutations;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
export { Permutation }
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { powerSet , subSet } from "./Set/index.js";
|
|
2
|
-
import { Base } from "./Conversion/index.js";
|
|
3
|
-
import {
|
|
4
|
-
Permutation,
|
|
5
|
-
} from "./Permutation/index.js"
|
|
6
|
-
import {
|
|
7
|
-
Combinaison,
|
|
8
|
-
combinaison,
|
|
9
|
-
} from "./Combinaison/index.js"
|
|
10
|
-
|
|
11
|
-
export{
|
|
12
|
-
Base,Permutation,Combinaison,combinaison,powerSet,subSet}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
// Mixed calcul
|
|
2
|
-
const sum=(...x)=>{
|
|
3
|
-
if(x.every(n=>typeof n==="number")){
|
|
4
|
-
let s = x[0];
|
|
5
|
-
for (let i = 1; i < x.length; i++) s += x[i];
|
|
6
|
-
return s;
|
|
7
|
-
}
|
|
8
|
-
const Y=[];
|
|
9
|
-
for(let i=0;i<x.length;i++){
|
|
10
|
-
if(x[i] instanceof Array)Y.push(sum(...x[i]));
|
|
11
|
-
else if(x[i] instanceof Object){
|
|
12
|
-
Y.push(sum(...Object.values(x[i])))
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return Y.length===1?Y[0]:Y;
|
|
16
|
-
}
|
|
17
|
-
const prod=(...x)=>{
|
|
18
|
-
if(x.every(n=>typeof n==="number")){
|
|
19
|
-
let p = x[0];
|
|
20
|
-
for (let i = 1; i < x.length; i++) p *= x[i];
|
|
21
|
-
return p;
|
|
22
|
-
}
|
|
23
|
-
const Y=[];
|
|
24
|
-
for(let i=0;i<x.length;i++){
|
|
25
|
-
if(x[i] instanceof Array)Y.push(prod(...x[i]));
|
|
26
|
-
else if(x[i] instanceof Object){
|
|
27
|
-
Y.push(prod(...Object.values(x[i])))
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return Y.length===1?Y[0]:Y;
|
|
31
|
-
}
|
|
32
|
-
// const min=(...num)=>{
|
|
33
|
-
// if(num.every(n=>typeof n==="number"))return Math.min(...num);
|
|
34
|
-
// const Y=[];
|
|
35
|
-
// for(let i=0;i<num.length;i++){
|
|
36
|
-
// if(num[i] instanceof Array)Y.push(min(...num[i]));
|
|
37
|
-
// else if(num[i] instanceof Object){
|
|
38
|
-
// Y.push(
|
|
39
|
-
// Object.fromEntries(
|
|
40
|
-
// [Object.entries(num[i]).sort((a,b)=>a[1]-b[1])[0]]
|
|
41
|
-
// )
|
|
42
|
-
// )
|
|
43
|
-
// }
|
|
44
|
-
// }
|
|
45
|
-
// return Y.length===1?Y[0]:Y;
|
|
46
|
-
// }
|
|
47
|
-
// const max=(...num)=>{
|
|
48
|
-
// if(num.every(n=>typeof n==="number"))return Math.max(...num);
|
|
49
|
-
// const Y=[];
|
|
50
|
-
// for(let i=0;i<num.length;i++){
|
|
51
|
-
// if(num[i] instanceof Array)Y.push(min(...num[i]));
|
|
52
|
-
// else if(num[i] instanceof Object){
|
|
53
|
-
// Y.push(
|
|
54
|
-
// Object.fromEntries(
|
|
55
|
-
// [Object.entries(num[i]).sort((a,b)=>b[1]-a[1])[0]]
|
|
56
|
-
// )
|
|
57
|
-
// )
|
|
58
|
-
// }
|
|
59
|
-
// }
|
|
60
|
-
// return Y.length===1?Y[0]:Y;
|
|
61
|
-
// }
|
|
62
|
-
const accum=(...num)=>{
|
|
63
|
-
if(num.every(n=>typeof n==="number")){
|
|
64
|
-
let acc = num.reduce((x, y) => [...x, x[x.length - 1] + y], [0]);
|
|
65
|
-
acc.shift();
|
|
66
|
-
return acc;
|
|
67
|
-
}
|
|
68
|
-
const Y=[];
|
|
69
|
-
for(let i=0;i<num.length;i++){
|
|
70
|
-
if(num[i] instanceof Array)Y.push(accum(...num[i]));
|
|
71
|
-
else if(num[i] instanceof Object){
|
|
72
|
-
Y.push(null
|
|
73
|
-
// Object.fromEntries(
|
|
74
|
-
// [Object.entries(num[i]).sort((a,b)=>b[1]-a[1])[0]]
|
|
75
|
-
// )
|
|
76
|
-
)
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return Y.length===1?Y[0]:Y;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// sort
|
|
83
|
-
|
|
84
|
-
export{
|
|
85
|
-
sum,
|
|
86
|
-
prod,
|
|
87
|
-
// min,
|
|
88
|
-
// max,
|
|
89
|
-
accum
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
//moy
|
|
93
|
-
//med
|
|
94
|
-
//variance
|
|
95
|
-
//std
|
|
96
|
-
//mode
|
|
97
|
-
//acccum
|
|
98
|
-
//min2max
|
|
99
|
-
//max2min
|
|
100
|
-
//percentile
|