math-exercises 3.0.215 → 3.0.216

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.
Files changed (114) hide show
  1. package/lib/exercises/math/arithmetic/whichDayInXDays.d.ts.map +1 -1
  2. package/lib/exercises/math/arithmetic/whichDayInXDays.js +2 -1
  3. package/lib/exercises/math/complex/unitRoots/giveOneSolutionToComplexPowNEqualsOne.js +1 -1
  4. package/lib/exercises/math/conversion/clock/index.d.ts +0 -1
  5. package/lib/exercises/math/conversion/clock/index.d.ts.map +1 -1
  6. package/lib/exercises/math/conversion/clock/index.js +1 -1
  7. package/lib/exercises/math/graphs/adjacentMatrixPath.d.ts +10 -0
  8. package/lib/exercises/math/graphs/adjacentMatrixPath.d.ts.map +1 -0
  9. package/lib/exercises/math/graphs/adjacentMatrixPath.js +89 -0
  10. package/lib/exercises/math/graphs/edgesNumberFromSummitsDegrees.d.ts +7 -0
  11. package/lib/exercises/math/graphs/edgesNumberFromSummitsDegrees.d.ts.map +1 -0
  12. package/lib/exercises/math/graphs/edgesNumberFromSummitsDegrees.js +98 -0
  13. package/lib/exercises/math/graphs/eulerianChainFromAdjacentMatrix.d.ts +8 -0
  14. package/lib/exercises/math/graphs/eulerianChainFromAdjacentMatrix.d.ts.map +1 -0
  15. package/lib/exercises/math/graphs/eulerianChainFromAdjacentMatrix.js +96 -0
  16. package/lib/exercises/math/graphs/graphsChainOrPathOfLengthN.d.ts +15 -0
  17. package/lib/exercises/math/graphs/graphsChainOrPathOfLengthN.d.ts.map +1 -0
  18. package/lib/exercises/math/graphs/graphsChainOrPathOfLengthN.js +262 -0
  19. package/lib/exercises/math/graphs/graphsCheckIsConnectedUndirectedGraph.d.ts +11 -0
  20. package/lib/exercises/math/graphs/graphsCheckIsConnectedUndirectedGraph.d.ts.map +1 -0
  21. package/lib/exercises/math/graphs/graphsCheckIsConnectedUndirectedGraph.js +178 -0
  22. package/lib/exercises/math/graphs/graphsCheckIsSameGraph.d.ts +19 -0
  23. package/lib/exercises/math/graphs/graphsCheckIsSameGraph.d.ts.map +1 -0
  24. package/lib/exercises/math/graphs/graphsCheckIsSameGraph.js +301 -0
  25. package/lib/exercises/math/graphs/graphsCheckIsVerticesAdjacent.d.ts +16 -0
  26. package/lib/exercises/math/graphs/graphsCheckIsVerticesAdjacent.d.ts.map +1 -0
  27. package/lib/exercises/math/graphs/graphsCheckIsVerticesAdjacent.js +207 -0
  28. package/lib/exercises/math/graphs/graphsDegreeOfVertex.d.ts +15 -0
  29. package/lib/exercises/math/graphs/graphsDegreeOfVertex.d.ts.map +1 -0
  30. package/lib/exercises/math/graphs/graphsDegreeOfVertex.js +232 -0
  31. package/lib/exercises/math/graphs/graphsOrderOfGraph.d.ts +14 -0
  32. package/lib/exercises/math/graphs/graphsOrderOfGraph.d.ts.map +1 -0
  33. package/lib/exercises/math/graphs/graphsOrderOfGraph.js +222 -0
  34. package/lib/exercises/math/graphs/index.d.ts +10 -0
  35. package/lib/exercises/math/graphs/index.d.ts.map +1 -0
  36. package/lib/exercises/math/graphs/index.js +9 -0
  37. package/lib/exercises/math/index.d.ts +1 -0
  38. package/lib/exercises/math/index.d.ts.map +1 -1
  39. package/lib/exercises/math/index.js +1 -0
  40. package/lib/exercises/math/matrices/areMatricesInverse.d.ts +9 -0
  41. package/lib/exercises/math/matrices/areMatricesInverse.d.ts.map +1 -0
  42. package/lib/exercises/math/matrices/areMatricesInverse.js +106 -0
  43. package/lib/exercises/math/matrices/computeFixedMatrixInRecurrenceSequence.d.ts +9 -0
  44. package/lib/exercises/math/matrices/computeFixedMatrixInRecurrenceSequence.d.ts.map +1 -0
  45. package/lib/exercises/math/matrices/computeFixedMatrixInRecurrenceSequence.js +144 -0
  46. package/lib/exercises/math/matrices/findInversedMatrixFromSystem.d.ts +8 -0
  47. package/lib/exercises/math/matrices/findInversedMatrixFromSystem.d.ts.map +1 -0
  48. package/lib/exercises/math/matrices/findInversedMatrixFromSystem.js +148 -0
  49. package/lib/exercises/math/matrices/index.d.ts +12 -0
  50. package/lib/exercises/math/matrices/index.d.ts.map +1 -1
  51. package/lib/exercises/math/matrices/index.js +12 -0
  52. package/lib/exercises/math/matrices/isMatrixTransitionMatrix.d.ts +8 -0
  53. package/lib/exercises/math/matrices/isMatrixTransitionMatrix.d.ts.map +1 -0
  54. package/lib/exercises/math/matrices/isMatrixTransitionMatrix.js +132 -0
  55. package/lib/exercises/math/matrices/matrixBuildMatrixFromCoefficients.d.ts +8 -0
  56. package/lib/exercises/math/matrices/matrixBuildMatrixFromCoefficients.d.ts.map +1 -0
  57. package/lib/exercises/math/matrices/matrixBuildMatrixFromCoefficients.js +152 -0
  58. package/lib/exercises/math/matrices/matrixCheckIsSymmetrical.d.ts +8 -0
  59. package/lib/exercises/math/matrices/matrixCheckIsSymmetrical.d.ts.map +1 -0
  60. package/lib/exercises/math/matrices/matrixCheckIsSymmetrical.js +155 -0
  61. package/lib/exercises/math/matrices/matrixComputeDetOfMat2.d.ts +8 -0
  62. package/lib/exercises/math/matrices/matrixComputeDetOfMat2.d.ts.map +1 -0
  63. package/lib/exercises/math/matrices/matrixComputeDetOfMat2.js +142 -0
  64. package/lib/exercises/math/matrices/matrixComputeInverseOfMat2.d.ts +8 -0
  65. package/lib/exercises/math/matrices/matrixComputeInverseOfMat2.d.ts.map +1 -0
  66. package/lib/exercises/math/matrices/matrixComputeInverseOfMat2.js +237 -0
  67. package/lib/exercises/math/matrices/matrixComputeLinearCombination.d.ts +15 -0
  68. package/lib/exercises/math/matrices/matrixComputeLinearCombination.d.ts.map +1 -0
  69. package/lib/exercises/math/matrices/matrixComputeLinearCombination.js +232 -0
  70. package/lib/exercises/math/matrices/matrixComputePower.d.ts +12 -0
  71. package/lib/exercises/math/matrices/matrixComputePower.d.ts.map +1 -0
  72. package/lib/exercises/math/matrices/matrixComputePower.js +230 -0
  73. package/lib/exercises/math/matrices/matrixComputeProduct.d.ts +9 -0
  74. package/lib/exercises/math/matrices/matrixComputeProduct.d.ts.map +1 -0
  75. package/lib/exercises/math/matrices/matrixComputeProduct.js +178 -0
  76. package/lib/exercises/math/matrices/writeMatrixAssociatedToSystem.d.ts +8 -0
  77. package/lib/exercises/math/matrices/writeMatrixAssociatedToSystem.d.ts.map +1 -0
  78. package/lib/exercises/math/matrices/writeMatrixAssociatedToSystem.js +105 -0
  79. package/lib/exercises/vea/matrixVEA.d.ts +2 -0
  80. package/lib/exercises/vea/matrixVEA.d.ts.map +1 -0
  81. package/lib/exercises/vea/matrixVEA.js +1 -0
  82. package/lib/index.d.ts +86 -13
  83. package/lib/index.d.ts.map +1 -1
  84. package/lib/math/geometry/point.d.ts.map +1 -1
  85. package/lib/math/geometry/point.js +3 -1
  86. package/lib/math/graphs/graph.d.ts +43 -0
  87. package/lib/math/graphs/graph.d.ts.map +1 -0
  88. package/lib/math/graphs/graph.js +391 -0
  89. package/lib/math/matrices/matrix.d.ts +42 -3
  90. package/lib/math/matrices/matrix.d.ts.map +1 -1
  91. package/lib/math/matrices/matrix.js +173 -7
  92. package/lib/math/matrices/parseMatrix.d.ts +3 -0
  93. package/lib/math/matrices/parseMatrix.d.ts.map +1 -0
  94. package/lib/math/matrices/parseMatrix.js +22 -0
  95. package/lib/math/systems/generalSystem.d.ts +2 -0
  96. package/lib/math/systems/generalSystem.d.ts.map +1 -1
  97. package/lib/math/systems/generalSystem.js +5 -0
  98. package/lib/math/utils/graphs/graphRenderer.d.ts +25 -0
  99. package/lib/math/utils/graphs/graphRenderer.d.ts.map +1 -0
  100. package/lib/math/utils/graphs/graphRenderer.js +123 -0
  101. package/lib/playground.d.ts +6 -1
  102. package/lib/playground.d.ts.map +1 -1
  103. package/lib/playground.js +6 -5
  104. package/lib/tree/parsers/latexParser.d.ts +1 -1
  105. package/lib/tree/utilities/nodeSimplifier.d.ts +1 -1
  106. package/lib/types/keyIds.d.ts +2 -0
  107. package/lib/types/keyIds.d.ts.map +1 -1
  108. package/lib/utils/arrays/arrayChunks.d.ts +9 -0
  109. package/lib/utils/arrays/arrayChunks.d.ts.map +1 -0
  110. package/lib/utils/arrays/arrayChunks.js +34 -0
  111. package/lib/utils/strings/ordinalSuffixed.d.ts +2 -0
  112. package/lib/utils/strings/ordinalSuffixed.d.ts.map +1 -0
  113. package/lib/utils/strings/ordinalSuffixed.js +5 -0
  114. package/package.json +7 -1
@@ -1,10 +1,51 @@
1
- import { MultiplyNode } from "../../tree/nodes/operators/multiplyNode.js";
1
+ import { opposite } from "../../tree/nodes/functions/oppositeNode.js";
2
+ import { reifyAlgebraic, } from "../../tree/nodes/nodeConstructor.js";
3
+ import { add } from "../../tree/nodes/operators/addNode.js";
4
+ import { frac } from "../../tree/nodes/operators/fractionNode.js";
5
+ import { multiply, MultiplyNode, } from "../../tree/nodes/operators/multiplyNode.js";
2
6
  import { SubstractNode } from "../../tree/nodes/operators/substractNode.js";
7
+ import { NodeComparator } from "../../tree/utilities/nodeComparator.js";
8
+ import { zip } from "../../utils/arrays/arrayZip.js";
9
+ import { transpose } from "../../utils/arrays/transpose.js";
10
+ import { doWhile } from "../../utils/doWhile.js";
3
11
  import { randint } from "../utils/random/randint.js";
4
12
  export class MatrixConstructor {
5
- static random(rows, cols) {
6
- const elts = Array.from(Array(rows), (_) => Array.from(Array(cols), (_) => randint(-10, 11).toTree()));
7
- return new Matrix(elts);
13
+ static random(rows, cols, opts) {
14
+ const allowIdentity = opts?.allowIdentity ?? false;
15
+ const elementsOpts = opts?.elementsOpts ?? [-10, 11];
16
+ const mat = doWhile(() => new Matrix(Array.from(Array(rows), (_) => Array.from(Array(cols), (_) => randint(...elementsOpts).toTree()))), (m) => !allowIdentity && m.isIdentity());
17
+ return mat;
18
+ }
19
+ static identity(order) {
20
+ return new Matrix(Array.from(Array(order), (_, i) => Array.from(Array(order), (_, i2) => i === i2 ? (1).toTree() : (0).toTree())));
21
+ }
22
+ static randomInversible(rows, cols, opts) {
23
+ const mat = doWhile(() => MatrixConstructor.random(rows, cols, opts), (m) => {
24
+ const det = m.determinant().evaluate();
25
+ return det === 0 || (!!opts?.niceInversible && Math.abs(det) > 10);
26
+ });
27
+ return mat;
28
+ }
29
+ static fromIdentifiers(identifiers) {
30
+ return new Matrix(identifiers.elementsIds.map((row) => row.map((cell) => reifyAlgebraic(cell))));
31
+ }
32
+ static emptyVarMatrix(nbRows, nbCols) {
33
+ const nodeVarEmpty = "".toTree();
34
+ const elements = [...Array(nbRows).keys()].map(() => [...Array(nbCols).keys()].map(() => nodeVarEmpty));
35
+ return new Matrix(elements);
36
+ }
37
+ static randomAdjacent(length, opts) {
38
+ const nbs = Array.from({ length }, () => Array(length).fill(0));
39
+ for (let i = 0; i < length; i++) {
40
+ for (let j = 0; j <= i; j++) {
41
+ if (!opts?.adjacentAllowLoop && j === i)
42
+ nbs[i][j] = 0;
43
+ else
44
+ nbs[i][j] = randint(0, 2);
45
+ nbs[j][i] = nbs[i][j];
46
+ }
47
+ }
48
+ return new Matrix(nbs.map((row) => row.map((nb) => nb.toTree())));
8
49
  }
9
50
  }
10
51
  export class Matrix {
@@ -16,15 +57,140 @@ export class Matrix {
16
57
  this.columns = elements[0].length;
17
58
  this.rows = elements.length;
18
59
  }
60
+ transposed() {
61
+ return new Matrix(transpose(this.elements));
62
+ }
63
+ isSymmetrical() {
64
+ return [...new Array(this.rows).keys()]
65
+ .flatMap((i) => [...new Array(this.columns).keys()].map((j) => [i, j]))
66
+ .every(([i, j]) => NodeComparator.isEqualViaSub(this.elements[i][j], this.elements[j][i]));
67
+ }
68
+ symmetrized() {
69
+ return this.add(this.transposed()).times(frac(1, 2));
70
+ }
71
+ toIdentifiers() {
72
+ return {
73
+ id: "matrix",
74
+ elementsIds: this.elements.map((row) => row.map((cell) => cell.toIdentifiers())),
75
+ };
76
+ }
19
77
  determinant() {
20
78
  if (this.rows === 2 && this.columns === 2) {
21
- return new SubstractNode(new MultiplyNode(this.elements[0][0], this.elements[1][1]), new MultiplyNode(this.elements[0][1], this.elements[1][0])).simplify();
79
+ return new SubstractNode(new MultiplyNode(this.elements[0][0], this.elements[1][1]), new MultiplyNode(this.elements[0][1], this.elements[1][0]));
22
80
  }
23
81
  throw Error("general determinant not implemented yet");
24
82
  }
83
+ toInversed() {
84
+ if (this.rows !== 2 || this.columns !== 2)
85
+ throw Error("general inverse not implemented yet");
86
+ const det = this.determinant();
87
+ if (det.simplify().toTex() === "0")
88
+ throw Error("matrix is not inversible");
89
+ return new Matrix([
90
+ [this.elements[1][1], opposite(this.elements[0][1])],
91
+ [opposite(this.elements[1][0]), this.elements[0][0]],
92
+ ]).times(frac(1, det));
93
+ }
94
+ isIdentity() {
95
+ if (this.rows !== this.columns) {
96
+ return false;
97
+ }
98
+ return (this.elements.every((row, index) => row[index].equals((1).toTree())) &&
99
+ this.elements.every((row, index) => row.every((cell, index2) => cell.equals((0).toTree()) || index === index2)));
100
+ }
101
+ isTransition() {
102
+ return (this.elements
103
+ .flat()
104
+ .every((x) => x.evaluate() >= 0 && x.evaluate() <= 1) &&
105
+ this.elements.every((row) => row
106
+ .reduce((acc, curr) => add(acc, curr).simplify(), (0).toTree())
107
+ .evaluate() === 1));
108
+ }
109
+ inverse() {
110
+ if (this.rows === 2 && this.columns === 2) {
111
+ const nodeDet = this.determinant().simplify({ towardsDistribute: true });
112
+ if (NodeComparator.isEqualViaSub(nodeDet, (0).toTree())) {
113
+ return undefined;
114
+ }
115
+ else {
116
+ const [[a, b], [c, d]] = this.elements;
117
+ return new Matrix([
118
+ [d, opposite(b)],
119
+ [opposite(c), a],
120
+ ]).times(frac(1, nodeDet));
121
+ }
122
+ }
123
+ throw Error("general inverse not implemented yet");
124
+ }
125
+ density() {
126
+ const nbElementsNonZero = this.elements
127
+ .flat()
128
+ .filter((elt) => !NodeComparator.isEqualViaSub(elt, (0).toTree())).length;
129
+ return nbElementsNonZero / (this.rows * this.columns);
130
+ }
131
+ matForMapFunc(func) {
132
+ const arrElementMapped = this.elements.map((row, i) => row.map((elt, j) => func(elt, i, j)));
133
+ return new Matrix(arrElementMapped);
134
+ }
135
+ times(k) {
136
+ const arrElementScaled = this.elements.map((row) => row.map((elt) => multiply(k, elt)));
137
+ return new Matrix(arrElementScaled);
138
+ }
139
+ opposite() {
140
+ return this.times((-1).toTree());
141
+ }
142
+ isMatAdditionPossible(matPrime) {
143
+ return this.rows === matPrime.rows && this.columns === matPrime.columns;
144
+ }
145
+ add(matPrime) {
146
+ const arrElementSum = zip(this.elements, matPrime.elements).map(([row, rowPrime]) => row.map((elt, i) => add(elt, rowPrime[i])));
147
+ return new Matrix(arrElementSum);
148
+ }
149
+ substract(matPrime) {
150
+ return this.add(matPrime.opposite());
151
+ }
152
+ isMatProductPossible(matPrime) {
153
+ return this.rows === matPrime.columns;
154
+ }
155
+ matrixProduct(matPrime) {
156
+ const matPrimeTransposed = matPrime.transposed();
157
+ const arrElementProduct = this.elements.map((row) => matPrimeTransposed.elements.map((column) => zip(row, column).reduce((acc, [nodeAik, nodeBkj], i) => {
158
+ const nodeAikBkj = multiply(nodeAik, nodeBkj, {
159
+ forceTimesSign: true,
160
+ });
161
+ if (i === 0) {
162
+ return nodeAikBkj;
163
+ }
164
+ else {
165
+ return add(acc, nodeAikBkj);
166
+ }
167
+ }, (0).toTree())));
168
+ return new Matrix(arrElementProduct);
169
+ }
170
+ power(exponent) {
171
+ return [...Array(exponent).keys()].reduce((acc, i) => {
172
+ if (i === 0) {
173
+ return this;
174
+ }
175
+ else {
176
+ return acc.matrixProduct(this);
177
+ }
178
+ }, this);
179
+ }
180
+ equals(matPrime) {
181
+ return this.elements.every((row, i) => row.every((elt, j) => {
182
+ const eltPrime = matPrime.elements[i][j];
183
+ return (NodeComparator.isEqualViaSub(eltPrime, elt) ||
184
+ NodeComparator.isEqualViaFrac(eltPrime, elt));
185
+ }));
186
+ }
25
187
  toTex() {
26
188
  return `\\begin{pmatrix}${this.elements
27
- .map((row, index) => `${row.map((cell) => cell.toTex()).join("&")} ${index < this.elements.length - 1 ? "\\\\[6pt]" : ""}`)
28
- .join("")}\\end{pmatrix}`;
189
+ .map((row) => `${row.map((cell) => cell.toTex()).join("&")}`)
190
+ .join("\\\\")}\\end{pmatrix}`;
191
+ }
192
+ simplify(simplifyOpts) {
193
+ const arrElementSimplified = this.elements.map((row) => row.map((elt) => elt.simplify(simplifyOpts)));
194
+ return new Matrix(arrElementSimplified);
29
195
  }
30
196
  }
@@ -0,0 +1,3 @@
1
+ import { Matrix } from "./matrix.js";
2
+ export declare const parseMatrix: (tex: string) => Matrix;
3
+ //# sourceMappingURL=parseMatrix.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseMatrix.d.ts","sourceRoot":"","sources":["../../../src/math/matrices/parseMatrix.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,eAAO,MAAM,WAAW,GAAI,KAAK,MAAM,KAAG,MAyBzC,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { parseAlgebraic } from "../../tree/parsers/latexParser.js";
2
+ import { Matrix } from "./matrix.js";
3
+ export const parseMatrix = (tex) => {
4
+ const parseMatrixToArrArrStr = (input) => {
5
+ // Extrait le contenu entre \begin{...} et \end{...}
6
+ const match = input.match(/\\begin\{[a-zA-Z*]+\}([\s\S]*)\\end\{[a-zA-Z*]+\}/);
7
+ const content = match ? match[1] : undefined;
8
+ if (content) {
9
+ return content
10
+ .split("\\\\") // sépare les lignes
11
+ .map((row) => row.trim())
12
+ .filter((row) => row.length > 0) // ignore une éventuelle ligne vide en fin
13
+ .map((row) => row.split("&").map((cell) => cell.trim()));
14
+ }
15
+ else {
16
+ throw new Error("Unsupported tex: " + tex);
17
+ }
18
+ };
19
+ const elts = parseMatrixToArrArrStr(tex).map((row) => row.map((str) => parseAlgebraic(str)));
20
+ const mat = new Matrix(elts);
21
+ return mat;
22
+ };
@@ -1,6 +1,7 @@
1
1
  import { AlgebraicNode, SimplifyOptions } from "../../tree/nodes/algebraicNode.js";
2
2
  import { EqualNode } from "../../tree/nodes/equations/equalNode.js";
3
3
  import { NodeIdentifiers } from "../../tree/nodes/nodeConstructor.js";
4
+ import { Matrix } from "../matrices/matrix.js";
4
5
  export declare abstract class GeneralSystemConstructor {
5
6
  static random(): GeneralSystem;
6
7
  static niceValues(): GeneralSystem;
@@ -17,6 +18,7 @@ export declare class GeneralSystem {
17
18
  getEqualNodes(varNames?: string[]): EqualNode[];
18
19
  checkCouple(x: AlgebraicNode, y: AlgebraicNode): boolean;
19
20
  multiplyEquation(nodes: AlgebraicNode[]): GeneralSystem;
21
+ getMatrix(): Matrix;
20
22
  solve(): {
21
23
  x: AlgebraicNode;
22
24
  y: AlgebraicNode;
@@ -1 +1 @@
1
- {"version":3,"file":"generalSystem.d.ts","sourceRoot":"","sources":["../../../src/math/systems/generalSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,eAAe,EAChB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAS,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAC3E,OAAO,EACL,eAAe,EAEhB,MAAM,qCAAqC,CAAC;AAU7C,8BAAsB,wBAAwB;IAC5C,MAAM,CAAC,MAAM;IAeb,MAAM,CAAC,UAAU;IAiBjB,MAAM,CAAC,eAAe,CAAC,GAAG,EAAE,wBAAwB;CAKrD;AAED,MAAM,MAAM,wBAAwB,GAAG;IACrC,SAAS,EAAE,eAAe,EAAE,EAAE,CAAC;CAChC,CAAC;AAEF,qBAAa,aAAa;IACxB,MAAM,EAAE,aAAa,EAAE,EAAE,CAAC;gBAId,MAAM,EAAE,CAAC,aAAa,GAAG,MAAM,CAAC,EAAE,EAAE;IAKhD,aAAa,IAAI,wBAAwB;IAKzC,QAAQ,CAAC,IAAI,CAAC,EAAE,eAAe;IAM/B,aAAa,CAAC,QAAQ,GAAE,MAAM,EAAe;IAU7C,WAAW,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,EAAE,aAAa;IAQ9C,gBAAgB,CAAC,KAAK,EAAE,aAAa,EAAE;IAUvC,KAAK;;;;IAoDL,KAAK,CAAC,QAAQ,GAAE,MAAM,EAAe;IAerC,eAAe,CACb,QAAQ,GAAE,MAAM,EAAe,EAC/B,eAAe,GAAE,OAAc;CAqIlC"}
1
+ {"version":3,"file":"generalSystem.d.ts","sourceRoot":"","sources":["../../../src/math/systems/generalSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,eAAe,EAChB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAS,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAC3E,OAAO,EACL,eAAe,EAEhB,MAAM,qCAAqC,CAAC;AAO7C,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAI/C,8BAAsB,wBAAwB;IAC5C,MAAM,CAAC,MAAM;IAeb,MAAM,CAAC,UAAU;IAiBjB,MAAM,CAAC,eAAe,CAAC,GAAG,EAAE,wBAAwB;CAKrD;AAED,MAAM,MAAM,wBAAwB,GAAG;IACrC,SAAS,EAAE,eAAe,EAAE,EAAE,CAAC;CAChC,CAAC;AAEF,qBAAa,aAAa;IACxB,MAAM,EAAE,aAAa,EAAE,EAAE,CAAC;gBAId,MAAM,EAAE,CAAC,aAAa,GAAG,MAAM,CAAC,EAAE,EAAE;IAKhD,aAAa,IAAI,wBAAwB;IAKzC,QAAQ,CAAC,IAAI,CAAC,EAAE,eAAe;IAM/B,aAAa,CAAC,QAAQ,GAAE,MAAM,EAAe;IAU7C,WAAW,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,EAAE,aAAa;IAQ9C,gBAAgB,CAAC,KAAK,EAAE,aAAa,EAAE;IAUvC,SAAS;IAIT,KAAK;;;;IAoDL,KAAK,CAAC,QAAQ,GAAE,MAAM,EAAe;IAerC,eAAe,CACb,QAAQ,GAAE,MAAM,EAAe,EAC/B,eAAe,GAAE,OAAc;CAqIlC"}
@@ -6,6 +6,7 @@ import { multiply } from "../../tree/nodes/operators/multiplyNode.js";
6
6
  import { substract } from "../../tree/nodes/operators/substractNode.js";
7
7
  import { doWhile } from "../../utils/doWhile.js";
8
8
  import { alignTex } from "../../utils/latex/alignTex.js";
9
+ import { Matrix } from "../matrices/matrix.js";
9
10
  import { lcm } from "../utils/arithmetic/lcm.js";
10
11
  import { randint } from "../utils/random/randint.js";
11
12
  export class GeneralSystemConstructor {
@@ -80,6 +81,10 @@ export class GeneralSystem {
80
81
  : this.coeffs[1],
81
82
  ]);
82
83
  }
84
+ getMatrix() {
85
+ const coeffs = this.coeffs.map((row) => row.slice(0, row.length - 1));
86
+ return new Matrix(coeffs);
87
+ }
83
88
  solve() {
84
89
  if (this.coeffs.length !== 2)
85
90
  throw Error("General system resolution not implemented yet");
@@ -0,0 +1,25 @@
1
+ import { Graph } from "../../graphs/graph.js";
2
+ import * as TSGraphViz from "ts-graphviz";
3
+ import { Engine } from "@hpcc-js/wasm-graphviz";
4
+ export interface GraphNode {
5
+ label: string;
6
+ x: number;
7
+ y: number;
8
+ }
9
+ export interface GraphEdge {
10
+ from: string;
11
+ to: string;
12
+ }
13
+ export declare class GraphRenderer {
14
+ static convertToGraphVizGraph(graph: Graph): TSGraphViz.Digraph;
15
+ static renderToSVG(graph: Graph, layoutEngineIn?: Engine): string;
16
+ static convertSVGToNodesAndEdges(strSVG: string): {
17
+ nodes: GraphNode[];
18
+ edges: GraphEdge[];
19
+ };
20
+ static renderToNodesAndEdges(graph: Graph, layoutEngineIn?: Engine): {
21
+ nodes: GraphNode[];
22
+ edges: GraphEdge[];
23
+ };
24
+ }
25
+ //# sourceMappingURL=graphRenderer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphRenderer.d.ts","sourceRoot":"","sources":["../../../../src/math/utils/graphs/graphRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAE9C,OAAO,KAAK,UAAU,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAY,MAAM,wBAAwB,CAAC;AAM1D,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,qBAAa,aAAa;IACxB,MAAM,CAAC,sBAAsB,CAAC,KAAK,EAAE,KAAK,GAAG,UAAU,CAAC,OAAO;IAkE/D,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,cAAc,CAAC,EAAE,MAAM;IA0BxD,MAAM,CAAC,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG;QAChD,KAAK,EAAE,SAAS,EAAE,CAAC;QACnB,KAAK,EAAE,SAAS,EAAE,CAAC;KACpB;IAwDD,MAAM,CAAC,qBAAqB,CAAC,KAAK,EAAE,KAAK,EAAE,cAAc,CAAC,EAAE,MAAM;eA1DzD,SAAS,EAAE;eACX,SAAS,EAAE;;CA6DrB"}
@@ -0,0 +1,123 @@
1
+ import * as TSGraphViz from "ts-graphviz";
2
+ import { Graphviz } from "@hpcc-js/wasm-graphviz";
3
+ const graphviz = await Graphviz.load();
4
+ import { JSDOM } from "jsdom";
5
+ import { random } from "../../../utils/alea/random.js";
6
+ export class GraphRenderer {
7
+ static convertToGraphVizGraph(graph) {
8
+ const digraph = new TSGraphViz.Digraph();
9
+ // Create nodes
10
+ const dictGraphvizNode = Object.fromEntries(graph.vertexNames.map((nameVertex) => {
11
+ const graphvizNode = new TSGraphViz.Node(nameVertex, {});
12
+ return [nameVertex, graphvizNode];
13
+ }));
14
+ // Create edges between the nodes
15
+ const arrConnectionNoDuplicate = (() => {
16
+ const arrConnection = Object.entries(graph.dictConnections()).flatMap(([nameVertexStart, dictConnections]) => {
17
+ return Object.entries(dictConnections)
18
+ .filter(([_, isConnection]) => isConnection)
19
+ .map(([nameVertexEnd, _]) => [nameVertexStart, nameVertexEnd]);
20
+ });
21
+ if (graph.isDirected) {
22
+ return arrConnection;
23
+ }
24
+ else {
25
+ return arrConnection
26
+ .map(([nameVertexStart, nameVertexEnd]) => [nameVertexStart, nameVertexEnd].join("-"))
27
+ .reduce((acc, strEdge) => {
28
+ const strEdgeReversed = strEdge.split("").toReversed().join("");
29
+ if (acc.includes(strEdgeReversed)) {
30
+ //ignore
31
+ }
32
+ else {
33
+ acc = [...acc, strEdge];
34
+ }
35
+ return acc;
36
+ }, [])
37
+ .map((strEdge) => {
38
+ const [nameVertexStart, nameVertexEnd] = strEdge.split("-");
39
+ return [nameVertexStart, nameVertexEnd];
40
+ });
41
+ }
42
+ })();
43
+ const arrEdge = arrConnectionNoDuplicate.map(([nameVertexStart, nameVertexEnd]) => {
44
+ const [graphvizNodeStart, graphvizNodeEnd] = [
45
+ nameVertexStart,
46
+ nameVertexEnd,
47
+ ].map((nameVertex) => dictGraphvizNode[nameVertex]);
48
+ const graphvizEdge = new TSGraphViz.Edge([graphvizNodeStart, graphvizNodeEnd], {});
49
+ return graphvizEdge;
50
+ });
51
+ // Add elements to the graph
52
+ Object.entries(dictGraphvizNode).forEach(([_, graphvizNode]) => digraph.addNode(graphvizNode));
53
+ arrEdge.forEach((graphvizEdge) => digraph.addEdge(graphvizEdge));
54
+ return digraph;
55
+ }
56
+ static renderToSVG(graph, layoutEngineIn) {
57
+ const digraph = GraphRenderer.convertToGraphVizGraph(graph);
58
+ const dot = TSGraphViz.toDot(digraph);
59
+ // Render DOT to SVG
60
+ /*
61
+ const arrLayoutEngine = [
62
+ "circo",
63
+ "dot",
64
+ "fdp",
65
+ "neato",
66
+ "nop",
67
+ "nop2",
68
+ // "osage",
69
+ // "patchwork",
70
+ "sfdp",
71
+ "twopi",
72
+ ];
73
+ */
74
+ const layoutEngine = layoutEngineIn ?? random(["fdp", "circo"]);
75
+ const svg = graphviz.layout(dot, "svg", layoutEngine);
76
+ return svg;
77
+ }
78
+ static convertSVGToNodesAndEdges(strSVG) {
79
+ function parseSvgGraph(svgString) {
80
+ const domParser = new new JSDOM().window.DOMParser();
81
+ const doc = domParser.parseFromString(svgString, "image/svg+xml");
82
+ const svgEl = doc.querySelector("svg");
83
+ const height = parseFloat(svgEl?.getAttribute("height") ?? "0");
84
+ // Translation du groupe racine (pattern classique Graphviz)
85
+ const graphGroup = doc.querySelector("g.graph") ?? doc.querySelector("svg > g");
86
+ const transform = graphGroup?.getAttribute("transform") ?? "";
87
+ const match = transform.match(/translate\(([-\d.]+)[ ,]([-\d.]+)\)/);
88
+ const [tx, ty] = match
89
+ ? [parseFloat(match[1]), parseFloat(match[2])]
90
+ : [0, 0];
91
+ // Sommets
92
+ const nodes = Array.from(doc.querySelectorAll("g.node")).map((g) => {
93
+ const ellipse = g.querySelector("ellipse");
94
+ const text = g.querySelector("text");
95
+ const label = text?.textContent?.trim() ??
96
+ g.querySelector("title")?.textContent?.trim() ??
97
+ "";
98
+ const cx = parseFloat(ellipse?.getAttribute("cx") ?? "0");
99
+ const cy = parseFloat(ellipse?.getAttribute("cy") ?? "0");
100
+ return {
101
+ label,
102
+ x: cx + tx,
103
+ y: height - (cy + ty), // flip vertical SVG -> GeoGebra
104
+ };
105
+ });
106
+ // Arêtes : lues directement depuis le <title> de chaque g.edge (ex: "A->B")
107
+ const edges = Array.from(doc.querySelectorAll("g.edge"))
108
+ .map((g) => g.querySelector("title")?.textContent?.trim() ?? "")
109
+ .map((title) => {
110
+ const [from, to] = title.split(/-&gt;|->/).map((s) => s.trim());
111
+ return { from, to };
112
+ })
113
+ .filter((e) => Boolean(e.from && e.to));
114
+ return { nodes, edges };
115
+ }
116
+ const { nodes, edges } = parseSvgGraph(strSVG);
117
+ return { nodes, edges };
118
+ }
119
+ static renderToNodesAndEdges(graph, layoutEngineIn) {
120
+ const strSVG = this.renderToSVG(graph, layoutEngineIn);
121
+ return this.convertSVGToNodesAndEdges(strSVG);
122
+ }
123
+ }
@@ -1,2 +1,7 @@
1
- export declare const playground: () => void;
1
+ export declare const playground: () => Promise<void>;
2
+ /***
3
+ *
4
+ * !!TODO
5
+ * - j'ai l'impression que opposite(3).simplify() et numberNode(-3) ne passent pas tjrs "equals", j'ai du mal à comprendre pourquoi alors que opposite(3) se simplifie bien en numberNode
6
+ */
2
7
  //# sourceMappingURL=playground.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"playground.d.ts","sourceRoot":"","sources":["../src/playground.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,YAGtB,CAAC"}
1
+ {"version":3,"file":"playground.d.ts","sourceRoot":"","sources":["../src/playground.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,qBAAiB,CAAC;AAEzC;;;;GAIG"}
package/lib/playground.js CHANGED
@@ -1,5 +1,6 @@
1
- import { parseAlgebraic } from "./tree/parsers/latexParser.js";
2
- export const playground = () => {
3
- const a = "8^9\\cos^3";
4
- console.log(parseAlgebraic(a).toTex());
5
- };
1
+ export const playground = async () => { };
2
+ /***
3
+ *
4
+ * !!TODO
5
+ * - j'ai l'impression que opposite(3).simplify() et numberNode(-3) ne passent pas tjrs "equals", j'ai du mal à comprendre pourquoi alors que opposite(3) se simplifie bien en numberNode
6
+ */
@@ -7,6 +7,6 @@ type ParserOptions = {
7
7
  allowStartingPower?: boolean;
8
8
  };
9
9
  export declare const parseAlgebraic: (latex: string, opts?: ParserOptions) => AlgebraicNode | IDontKnowNode;
10
- export declare const parseLatex: (latex: string) => AlgebraicNode | EqualNode | InequationNode | IDontKnowNode;
10
+ export declare const parseLatex: (latex: string) => AlgebraicNode | EqualNode | IDontKnowNode | InequationNode;
11
11
  export {};
12
12
  //# sourceMappingURL=latexParser.d.ts.map
@@ -2,7 +2,7 @@ import { AlgebraicNode, SimplifyOptions } from "../nodes/algebraicNode.js";
2
2
  import { ToTexOptions } from "../nodes/node.js";
3
3
  export declare abstract class NodeSimplifier {
4
4
  static getDepth: <T extends AlgebraicNode>(algebraicNode: T, simplifyOpts: SimplifyOptions, toTexOptions?: ToTexOptions) => number;
5
- static getPEMDASPriority: (algebraicNode: AlgebraicNode) => 1 | 0 | 2 | 100 | -1 | 3 | 5 | 4;
5
+ static getPEMDASPriority: (algebraicNode: AlgebraicNode) => 1 | 0 | 2 | 100 | -1 | 5 | 3 | 4;
6
6
  static nodesSortedByPEMDASPriorityAsc: (nodes: AlgebraicNode[]) => AlgebraicNode[];
7
7
  static nodesStepByStep: <T extends AlgebraicNode>(algebraicNode: T, simplifyOpts: SimplifyOptions, simplifierOpts?: {
8
8
  isMultiTopLevel: boolean;
@@ -27,6 +27,8 @@ export type KeyId =
27
27
  | "guillemet" | "quote" | "hyphen" | "euro" | "space" | "underscore" | "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z" | "É" | "È" | "Ç" | "À" | "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" | "é" | "è" | "à" | "ç" | "ù" | "ô"
28
28
  /**numbers */
29
29
  | "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
30
+ /**matrix*/
31
+ | "mat-2-2" | "det-2-2"
30
32
  /**atoms */
31
33
  | "Hydrogène" | "Hélium" | "Lithium" | "Béryllium" | "Bore" | "Carbone" | "Azote" | "Oxygène" | "Fluor" | "Néon" | "Sodium" | "Magnésium" | "Aluminium" | "Silicium" | "Phosphore" | "Soufre" | "Chlore" | "Argon" | "Potassium" | "Calcium" | "Scandium" | "Titane" | "Vanadium" | "Chrome" | "Manganèse" | "Fer" | "Cobalt" | "Nickel" | "Cuivre" | "Zinc" | "Gallium" | "Germanium" | "Arsenic" | "Sélénium" | "Brome" | "Krypton" | "Rubidium" | "Strontium" | "Yttrium" | "Zirconium" | "Niobium" | "Molybdène" | "Technétium" | "Ruthénium" | "Rhodium" | "Palladium" | "Argent" | "Cadmium" | "Indium" | "Étain" | "Antimoine" | "Tellure" | "Iode" | "Xénon" | "Césium" | "Baryum" | "Lanthane" | "Cérium" | "Praséodyme" | "Néodyme" | "Prométhium" | "Samarium" | "Europium" | "Gadolinium" | "Térbium" | "Dysprosium" | "Holmium" | "Erbium" | "Thulium" | "Ytterbium" | "Lutétium" | "Hafnium" | "Tantale" | "Tungstène" | "Rhénium" | "Osmium" | "Iridium" | "Platine" | "Or" | "Mercure" | "Thallium" | "Plomb" | "Bismuth" | "Polonium" | "Astate" | "Radon" | "Francium" | "Radium" | "Actinium" | "Thorium" | "Protactinium" | "Uranium" | "Neptunium" | "Plutonium" | "Américium" | "Curium" | "Berkélium" | "Californium" | "Einsteinium" | "Fermium" | "Mendélévium" | "Nobelium" | "Lawrencium" | "Rutherfordium" | "Dubnium" | "Seaborgium" | "Bohrium" | "Hassium" | "Meitnérium" | "Darmstadtium" | "Roentgenium" | "Copernicium" | "Nihonium" | "Flerovium" | "Moscovium" | "Livermorium" | "Tennessine" | "Oganesson"
32
34
  /**Molecules */
@@ -1 +1 @@
1
- {"version":3,"file":"keyIds.d.ts","sourceRoot":"","sources":["../../src/types/keyIds.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK;AACf,gBAAgB;AACd,YAAY,GACZ,aAAa,GACb,mBAAmB,GACnB,oBAAoB;AACtB,WAAW;GACT,IAAI,GACJ,KAAK,GACL,SAAS,GACT,IAAI,GACJ,KAAK,GACL,IAAI,GACJ,IAAI,GACJ,SAAS,GACT,SAAS,GACT,OAAO,GACP,eAAe;AAEjB,aAAa;GACX,QAAQ,GACR,OAAO,GACP,MAAM,GACN,YAAY,GACZ,KAAK,GACL,OAAO,GACP,QAAQ,GACR,KAAK;AAEP,WAAW;GACT,IAAI,GACJ,IAAI,GACJ,OAAO;AAET,cAAc;GACZ,gBAAgB,GAChB,QAAQ,GACR,SAAS,GACT,SAAS,GACT,SAAS,GACT,SAAS,GACT,WAAW,GACX,SAAS;AAEX,gBAAgB;GACd,MAAM,GACN,OAA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,GACX,UAAU,GACV,UAAU,GACV,WAAW,GACX,UAAU,GACV,YAAY,GACZ,WAAW,GACX,aAAa,GACb,YAAY,GACZ,YAAY,GACZ,YAAY,GACZ,YAAY,GACZ,eAAe,GACf,aAAa,GACb,UAAU,GACV,aAAa,GACb,QAAQ,GACR,SAAS,GACT,QAAQ,GACR,WAAW,GACX,UAAU,GACV,UAAU,GACV,WAAW,GACX,UAAU,GACV,YAAY,GACZ,UAAU,GACV,WAAW,GACX,WAAW,GACX,YAAY,GACZ,YAAY,GACZ,aAAa,GACb,WAAW,GACX,WAAW,GACX,WAAW,GACX,YAAY,GACZ,WAAW,GACX,eAAe,GACf,SAAS,GACT,UAAU,GACV,WAAW,GACX,UAAU,GACV,WAAW,GACX,WAAW,GACX,WAAW,GACX,WAAW,GACX,WAAW,GACX,YAAY,GACZ,QAAQ,GACR,WAAW,GACX,SAAS,GACT,WAAW,GACX,UAAU,GACV,WAAW,GACX,QAAQ,GACR,UAAU,GACV,SAAS,GACT,cAAc,GACd,OAAO,GACP,YAAY,GACZ,WAAW,GACX,QAAQ,GACR,YAAY,GACZ,QAAQ,GACR,aAAa,GACb,UAAU,GACV,QAAQ,GACR,YAAY,GACZ,WAAW,GACX,SAAS,GACT,WAAW,GACX,WAAW,GACX,SAAS,GACT,SAAS,GACT,UAAU,GACV,SAAS,GACT,WAAW,GACX,WAAW,GACX,WAAW,GACX,UAAU,GACV,QAAQ,GACR,QAAQ,GACR,WAAW,GACX,UAAU,GACV,UAAU,GACV,UAAU,GACV,WAAW,GACX,UAAU,GACV,SAAS,GACT,SAAS,GACT,WAAW,GACX,YAAY,GACZ,UAAU,GACV,aAAa,GACb,WAAW,GACX,QAAQ,GACR,WAAW,GACX,WAAW,CAAC"}
1
+ {"version":3,"file":"keyIds.d.ts","sourceRoot":"","sources":["../../src/types/keyIds.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK;AACf,gBAAgB;AACd,YAAY,GACZ,aAAa,GACb,mBAAmB,GACnB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,WAAW,GACX,WAAW,GACX,SAAS,GACT,SAAS,GACT,UAAU,GACV,SAAS,GACT,WAAW,GACX,WAAW,GACX,WAAW,GACX,UAAU,GACV,QAAQ,GACR,QAAQ,GACR,WAAW,GACX,UAAU,GACV,UAAU,GACV,UAAU,GACV,WAAW,GACX,UAAU,GACV,SAAS,GACT,SAAS,GACT,WAAW,GACX,YAAY,GACZ,UAAU,GACV,aAAa,GACb,WAAW,GACX,QAAQ,GACR,WAAW,GACX,WAAW,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Splits an array into chunks of random sizes.
3
+ * @param arr - The input array.
4
+ * @param minSize - Minimum chunk size (default: 2).
5
+ * @param maxSize - Maximum chunk size (default: arr.length).
6
+ * @returns An array of chunks.
7
+ */
8
+ export declare function splitIntoRandomChunks<T>(arr: T[], minSize?: number, maxSize?: number): T[][];
9
+ //# sourceMappingURL=arrayChunks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arrayChunks.d.ts","sourceRoot":"","sources":["../../../src/utils/arrays/arrayChunks.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EACrC,GAAG,EAAE,CAAC,EAAE,EACR,OAAO,GAAE,MAAU,EACnB,OAAO,CAAC,EAAE,MAAM,GACf,CAAC,EAAE,EAAE,CAmCP"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Splits an array into chunks of random sizes.
3
+ * @param arr - The input array.
4
+ * @param minSize - Minimum chunk size (default: 2).
5
+ * @param maxSize - Maximum chunk size (default: arr.length).
6
+ * @returns An array of chunks.
7
+ */
8
+ export function splitIntoRandomChunks(arr, minSize = 2, maxSize) {
9
+ if (!Array.isArray(arr)) {
10
+ throw new TypeError("Input must be an array.");
11
+ }
12
+ if (arr.length < 4)
13
+ return [];
14
+ // Ensure minSize is at least 2
15
+ minSize = Math.max(2, Math.floor(minSize));
16
+ maxSize = maxSize ? Math.floor(maxSize) : arr.length - 2;
17
+ if (minSize > maxSize) {
18
+ throw new Error("minSize cannot be greater than maxSize.");
19
+ }
20
+ const result = [];
21
+ let index = 0;
22
+ while (index < arr.length) {
23
+ // Remaining elements
24
+ const remaining = arr.length - index;
25
+ // Random chunk size between minSize and maxSize, but not more than remaining
26
+ let size = Math.min(remaining, Math.floor(Math.random() * (maxSize - minSize + 1)) + minSize);
27
+ if (index + size === arr.length - 1) {
28
+ size = size + 1;
29
+ }
30
+ result.push(arr.slice(index, index + size));
31
+ index += size;
32
+ }
33
+ return result;
34
+ }
@@ -0,0 +1,2 @@
1
+ export declare const ordinalSuffixed: (n: number, isMasculine?: boolean) => string;
2
+ //# sourceMappingURL=ordinalSuffixed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ordinalSuffixed.d.ts","sourceRoot":"","sources":["../../../src/utils/strings/ordinalSuffixed.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,GAAI,GAAG,MAAM,EAAE,qBAAmB,WAG7D,CAAC"}
@@ -0,0 +1,5 @@
1
+ export const ordinalSuffixed = (n, isMasculine = false) => {
2
+ if (n === 1)
3
+ return isMasculine ? `$${n}$-er` : `$${n}$-ère`;
4
+ return `$${n}$-ème`;
5
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "math-exercises",
3
3
  "type": "module",
4
- "version": "3.0.215",
4
+ "version": "3.0.216",
5
5
  "description": "Math exercises generator for middle school and high school",
6
6
  "main": "lib/index.js",
7
7
  "files": [
@@ -28,16 +28,22 @@
28
28
  "author": "Heureux Hasard",
29
29
  "license": "ISC",
30
30
  "dependencies": {
31
+ "@flatten-js/core": "^1.6.14",
32
+ "@hpcc-js/wasm-graphviz": "^1.29.1",
31
33
  "d3-node": "^4.0.1",
34
+ "jsdom": "^29.1.1",
32
35
  "katex": "^0.16.21",
33
36
  "lodash.isequal": "^4.5.0",
37
+ "ts-graphviz": "^3.0.7",
34
38
  "uuidv4": "^6.2.13"
35
39
  },
36
40
  "devDependencies": {
37
41
  "@eslint/js": "^9.34.0",
38
42
  "@types/cors": "^2.8.13",
43
+ "@types/deasync": "^0.1.5",
39
44
  "@types/express": "^4.17.17",
40
45
  "@types/jest": "^29.5.6",
46
+ "@types/jsdom": "^30.0.0",
41
47
  "@types/lodash.isequal": "^4.5.8",
42
48
  "@types/node": "^20.10.6",
43
49
  "body-parser": "^1.20.2",