math-exercises 3.0.198 → 3.0.200

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 (152) hide show
  1. package/lib/exercises/exercise.d.ts +14 -1
  2. package/lib/exercises/exercise.d.ts.map +1 -1
  3. package/lib/exercises/math/_debug/debugReorder1.d.ts +8 -0
  4. package/lib/exercises/math/_debug/debugReorder1.d.ts.map +1 -0
  5. package/lib/exercises/math/_debug/debugReorder1.js +81 -0
  6. package/lib/exercises/math/_debug/debugReorder2.d.ts +10 -0
  7. package/lib/exercises/math/_debug/debugReorder2.d.ts.map +1 -0
  8. package/lib/exercises/math/_debug/debugReorder2.js +88 -0
  9. package/lib/exercises/math/_debug/debugReorder3.d.ts +10 -0
  10. package/lib/exercises/math/_debug/debugReorder3.d.ts.map +1 -0
  11. package/lib/exercises/math/_debug/debugReorder3.js +81 -0
  12. package/lib/exercises/math/_debug/index.d.ts +3 -1
  13. package/lib/exercises/math/_debug/index.d.ts.map +1 -1
  14. package/lib/exercises/math/_debug/index.js +3 -1
  15. package/lib/exercises/math/calcul/factorial/index.d.ts +2 -0
  16. package/lib/exercises/math/calcul/factorial/index.d.ts.map +1 -0
  17. package/lib/exercises/math/calcul/factorial/index.js +1 -0
  18. package/lib/exercises/math/calcul/factorial/simplifyQuotientOfFactorialToProduct.d.ts +8 -0
  19. package/lib/exercises/math/calcul/factorial/simplifyQuotientOfFactorialToProduct.d.ts.map +1 -0
  20. package/lib/exercises/math/calcul/factorial/simplifyQuotientOfFactorialToProduct.js +199 -0
  21. package/lib/exercises/math/calculLitteral/equation/exp/expOfTrinomEquals1Equation.d.ts.map +1 -1
  22. package/lib/exercises/math/calculLitteral/equation/exp/expOfTrinomEquals1Equation.js +3 -0
  23. package/lib/exercises/math/calculLitteral/inequations/firstDegreeInequationsType3.d.ts.map +1 -1
  24. package/lib/exercises/math/calculLitteral/inequations/firstDegreeInequationsType3.js +58 -30
  25. package/lib/exercises/math/combinatory/combination/index.d.ts +3 -0
  26. package/lib/exercises/math/combinatory/combination/index.d.ts.map +1 -0
  27. package/lib/exercises/math/combinatory/combination/index.js +2 -0
  28. package/lib/exercises/math/combinatory/combination/mentalCalculateCombination.d.ts +11 -0
  29. package/lib/exercises/math/combinatory/combination/mentalCalculateCombination.d.ts.map +1 -0
  30. package/lib/exercises/math/combinatory/combination/mentalCalculateCombination.js +225 -0
  31. package/lib/exercises/math/combinatory/combination/writeCombinationFormulaUsingFactorial.d.ts +13 -0
  32. package/lib/exercises/math/combinatory/combination/writeCombinationFormulaUsingFactorial.d.ts.map +1 -0
  33. package/lib/exercises/math/combinatory/combination/writeCombinationFormulaUsingFactorial.js +285 -0
  34. package/lib/exercises/math/complex/addComplex.d.ts.map +1 -1
  35. package/lib/exercises/math/complex/addComplex.js +53 -7
  36. package/lib/exercises/math/complex/conjugateComplex.d.ts.map +1 -1
  37. package/lib/exercises/math/complex/conjugateComplex.js +48 -7
  38. package/lib/exercises/math/complex/mutiplyComplex.d.ts.map +1 -1
  39. package/lib/exercises/math/complex/mutiplyComplex.js +51 -18
  40. package/lib/exercises/math/complex/reAndIm.d.ts.map +1 -1
  41. package/lib/exercises/math/complex/reAndIm.js +35 -4
  42. package/lib/exercises/math/dataRepresentations/scatterPlot/scatterPlotInterpreting.d.ts.map +1 -1
  43. package/lib/exercises/math/dataRepresentations/scatterPlot/scatterPlotInterpreting.js +1 -1
  44. package/lib/exercises/math/derivation/derivative/trigo/cosSecondDegreeDerivative.d.ts.map +1 -1
  45. package/lib/exercises/math/derivation/derivative/trigo/cosSecondDegreeDerivative.js +47 -3
  46. package/lib/exercises/math/derivation/derivative/trigo/productOfSinAXPlusBCosCXPlusDDerivative.d.ts +9 -0
  47. package/lib/exercises/math/derivation/derivative/trigo/productOfSinAXPlusBCosCXPlusDDerivative.d.ts.map +1 -0
  48. package/lib/exercises/math/derivation/derivative/trigo/productOfSinAXPlusBCosCXPlusDDerivative.js +209 -0
  49. package/lib/exercises/math/derivation/derivative/trigo/sinAndCosMixedWithSquareDerivative.d.ts +9 -0
  50. package/lib/exercises/math/derivation/derivative/trigo/sinAndCosMixedWithSquareDerivative.d.ts.map +1 -0
  51. package/lib/exercises/math/derivation/derivative/trigo/sinAndCosMixedWithSquareDerivative.js +359 -0
  52. package/lib/exercises/math/derivation/derivative/trigo/sinCosDerivativeRewriteUsingCos2PlusSin2Equals1.d.ts +11 -0
  53. package/lib/exercises/math/derivation/derivative/trigo/sinCosDerivativeRewriteUsingCos2PlusSin2Equals1.d.ts.map +1 -0
  54. package/lib/exercises/math/derivation/derivative/trigo/sinCosDerivativeRewriteUsingCos2PlusSin2Equals1.js +445 -0
  55. package/lib/exercises/math/functions/affines/affineVarTableOnBoundedInterval.d.ts.map +1 -1
  56. package/lib/exercises/math/functions/affines/affineVarTableOnBoundedInterval.js +2 -3
  57. package/lib/exercises/math/functions/exponential/sign/expFunctionBasicSign.d.ts.map +1 -1
  58. package/lib/exercises/math/functions/exponential/sign/expFunctionBasicSign.js +3 -0
  59. package/lib/exercises/math/functions/sign/affineProductSign.d.ts.map +1 -1
  60. package/lib/exercises/math/functions/sign/affineProductSign.js +0 -4
  61. package/lib/exercises/math/index.d.ts +1 -0
  62. package/lib/exercises/math/index.d.ts.map +1 -1
  63. package/lib/exercises/math/index.js +1 -1
  64. package/lib/exercises/math/limits/sequenceGeometricLimit.d.ts.map +1 -1
  65. package/lib/exercises/math/limits/sequenceGeometricLimit.js +9 -0
  66. package/lib/exercises/math/primitive/constantPrimitive.d.ts +8 -5
  67. package/lib/exercises/math/primitive/constantPrimitive.d.ts.map +1 -1
  68. package/lib/exercises/math/primitive/constantPrimitive.js +40 -21
  69. package/lib/exercises/math/probaStat/stats2var/averagePoint.d.ts.map +1 -1
  70. package/lib/exercises/math/probaStat/stats2var/averagePoint.js +34 -2
  71. package/lib/exercises/math/sequences/geometric/graph/geometricFindThresholdFromGraph.d.ts +15 -0
  72. package/lib/exercises/math/sequences/geometric/graph/geometricFindThresholdFromGraph.d.ts.map +1 -0
  73. package/lib/exercises/math/sequences/geometric/graph/geometricFindThresholdFromGraph.js +255 -0
  74. package/lib/exercises/math/sequences/geometric/graph/geometricFindThresholdUsingCalculator.d.ts +15 -0
  75. package/lib/exercises/math/sequences/geometric/graph/geometricFindThresholdUsingCalculator.d.ts.map +1 -0
  76. package/lib/exercises/math/sequences/geometric/graph/geometricFindThresholdUsingCalculator.js +242 -0
  77. package/lib/exercises/math/sequences/geometric/graph/geometricPlaceFirstPoints.js +4 -4
  78. package/lib/exercises/math/sequences/geometric/graph/geometricSignOfReasonFromGraph.d.ts +12 -0
  79. package/lib/exercises/math/sequences/geometric/graph/geometricSignOfReasonFromGraph.d.ts.map +1 -0
  80. package/lib/exercises/math/sequences/geometric/graph/geometricSignOfReasonFromGraph.js +161 -0
  81. package/lib/exercises/math/sets/cartesianProduct/findCardinalOfCartesianProductOfFiniteSets.d.ts +10 -0
  82. package/lib/exercises/math/sets/cartesianProduct/findCardinalOfCartesianProductOfFiniteSets.d.ts.map +1 -0
  83. package/lib/exercises/math/sets/cartesianProduct/findCardinalOfCartesianProductOfFiniteSets.js +224 -0
  84. package/lib/exercises/math/sets/cartesianProduct/findCardinalOfCartesianProductOfFiniteSetsFromSituation.d.ts +18 -0
  85. package/lib/exercises/math/sets/cartesianProduct/findCardinalOfCartesianProductOfFiniteSetsFromSituation.d.ts.map +1 -0
  86. package/lib/exercises/math/sets/cartesianProduct/findCardinalOfCartesianProductOfFiniteSetsFromSituation.js +198 -0
  87. package/lib/exercises/math/sets/cartesianProduct/findCardinalOfPowEK.d.ts +10 -0
  88. package/lib/exercises/math/sets/cartesianProduct/findCardinalOfPowEK.d.ts.map +1 -0
  89. package/lib/exercises/math/sets/cartesianProduct/findCardinalOfPowEK.js +231 -0
  90. package/lib/exercises/math/sets/cartesianProduct/findNumberOfPasswordsWithLettersAndNumbers.d.ts +19 -0
  91. package/lib/exercises/math/sets/cartesianProduct/findNumberOfPasswordsWithLettersAndNumbers.d.ts.map +1 -0
  92. package/lib/exercises/math/sets/cartesianProduct/findNumberOfPasswordsWithLettersAndNumbers.js +187 -0
  93. package/lib/exercises/math/sets/cartesianProduct/index.d.ts +7 -0
  94. package/lib/exercises/math/sets/cartesianProduct/index.d.ts.map +1 -0
  95. package/lib/exercises/math/sets/cartesianProduct/index.js +6 -0
  96. package/lib/exercises/math/sets/cartesianProduct/proposeElementInCartesianProductOfFiniteSets.d.ts +15 -0
  97. package/lib/exercises/math/sets/cartesianProduct/proposeElementInCartesianProductOfFiniteSets.d.ts.map +1 -0
  98. package/lib/exercises/math/sets/cartesianProduct/proposeElementInCartesianProductOfFiniteSets.js +291 -0
  99. package/lib/exercises/math/sets/cartesianProduct/proposeElementInPowEK.d.ts +15 -0
  100. package/lib/exercises/math/sets/cartesianProduct/proposeElementInPowEK.d.ts.map +1 -0
  101. package/lib/exercises/math/sets/cartesianProduct/proposeElementInPowEK.js +274 -0
  102. package/lib/exercises/math/sets/combinations/findNumberOfCombinationsFromSituation.d.ts +17 -0
  103. package/lib/exercises/math/sets/combinations/findNumberOfCombinationsFromSituation.d.ts.map +1 -0
  104. package/lib/exercises/math/sets/combinations/findNumberOfCombinationsFromSituation.js +228 -0
  105. package/lib/exercises/math/sets/combinations/findNumberOfProductsOfCombinationsFromSituation.d.ts +17 -0
  106. package/lib/exercises/math/sets/combinations/findNumberOfProductsOfCombinationsFromSituation.d.ts.map +1 -0
  107. package/lib/exercises/math/sets/combinations/findNumberOfProductsOfCombinationsFromSituation.js +388 -0
  108. package/lib/exercises/math/sets/combinations/index.d.ts +4 -0
  109. package/lib/exercises/math/sets/combinations/index.d.ts.map +1 -0
  110. package/lib/exercises/math/sets/combinations/index.js +3 -0
  111. package/lib/exercises/math/sets/combinations/proposeCombination.d.ts +15 -0
  112. package/lib/exercises/math/sets/combinations/proposeCombination.d.ts.map +1 -0
  113. package/lib/exercises/math/sets/combinations/proposeCombination.js +347 -0
  114. package/lib/exercises/math/sets/partialPermutations/findNumberOfPartialPermutationsFromSituation.d.ts +16 -0
  115. package/lib/exercises/math/sets/partialPermutations/findNumberOfPartialPermutationsFromSituation.d.ts.map +1 -0
  116. package/lib/exercises/math/sets/partialPermutations/findNumberOfPartialPermutationsFromSituation.js +186 -0
  117. package/lib/exercises/math/sets/partialPermutations/findNumberOfPermutationsFromSituation.d.ts +17 -0
  118. package/lib/exercises/math/sets/partialPermutations/findNumberOfPermutationsFromSituation.d.ts.map +1 -0
  119. package/lib/exercises/math/sets/partialPermutations/findNumberOfPermutationsFromSituation.js +232 -0
  120. package/lib/exercises/math/sets/partialPermutations/index.d.ts +4 -0
  121. package/lib/exercises/math/sets/partialPermutations/index.d.ts.map +1 -0
  122. package/lib/exercises/math/sets/partialPermutations/index.js +3 -0
  123. package/lib/exercises/math/sets/partialPermutations/proposePartialPermutation.d.ts +15 -0
  124. package/lib/exercises/math/sets/partialPermutations/proposePartialPermutation.d.ts.map +1 -0
  125. package/lib/exercises/math/sets/partialPermutations/proposePartialPermutation.js +343 -0
  126. package/lib/exercises/math/spaceGeometry/vectors/spaceVectorLinearCombinationCoords.d.ts.map +1 -1
  127. package/lib/exercises/math/trigonometry/functions/parityOfCosAXTimesSinBX.d.ts +8 -0
  128. package/lib/exercises/math/trigonometry/functions/parityOfCosAXTimesSinBX.d.ts.map +1 -0
  129. package/lib/exercises/math/trigonometry/functions/parityOfCosAXTimesSinBX.js +193 -0
  130. package/lib/index.d.ts +15 -1
  131. package/lib/index.d.ts.map +1 -1
  132. package/lib/math/sets/setOperations.d.ts +9 -0
  133. package/lib/math/sets/setOperations.d.ts.map +1 -0
  134. package/lib/math/sets/setOperations.js +84 -0
  135. package/lib/math/sets/tuple.d.ts +12 -0
  136. package/lib/math/sets/tuple.d.ts.map +1 -0
  137. package/lib/math/sets/tuple.js +17 -0
  138. package/lib/server.js +28 -2
  139. package/lib/tests/pdfExo.test.js +2 -2
  140. package/lib/tests/pdfs/buildPDFForExercise.d.ts.map +1 -1
  141. package/lib/tests/pdfs/buildPDFForExercise.js +6 -0
  142. package/lib/tests/pdfs/quizPdfPreambule.d.ts.map +1 -1
  143. package/lib/tests/pdfs/quizPdfPreambule.js +1 -0
  144. package/lib/tests/pdfs/treeDiagramToLatex.d.ts +15 -0
  145. package/lib/tests/pdfs/treeDiagramToLatex.d.ts.map +1 -0
  146. package/lib/tests/pdfs/treeDiagramToLatex.js +49 -0
  147. package/lib/tests/questionTest.d.ts.map +1 -1
  148. package/lib/tests/questionTest.js +19 -0
  149. package/lib/tree/utilities/nodePrinter.d.ts +7 -0
  150. package/lib/tree/utilities/nodePrinter.d.ts.map +1 -0
  151. package/lib/tree/utilities/nodePrinter.js +36 -0
  152. package/package.json +1 -1
@@ -0,0 +1,224 @@
1
+ import { addValidProp, shuffleProps, tryToAddWrongProp, } from "../../../../exercises/exercise.js";
2
+ import { getDistinctQuestions } from "../../../../exercises/utils/getDistinctQuestions.js";
3
+ import { alignTex } from "../../../../utils/latex/alignTex.js";
4
+ import { shuffle } from "../../../../utils/alea/shuffle.js";
5
+ import { handleVEAError } from "../../../../utils/errors/handleVEAError.js";
6
+ import { NodeConstructor, } from "../../../../tree/nodes/nodeConstructor.js";
7
+ import { DiscreteSetNode } from "../../../../tree/nodes/sets/discreteSetNode.js";
8
+ import { isVariableNode, VariableNode, } from "../../../../tree/nodes/variables/variableNode.js";
9
+ import { random } from "../../../../utils/alea/random.js";
10
+ import { coinFlip } from "../../../../utils/alea/coinFlip.js";
11
+ import { multiply } from "../../../../tree/nodes/operators/multiplyNode.js";
12
+ import { add } from "../../../../tree/nodes/operators/addNode.js";
13
+ import { power } from "../../../../tree/nodes/operators/powerNode.js";
14
+ import { numberVEA } from "../../../../exercises/vea/numberVEA.js";
15
+ import { randint } from "../../../../math/utils/random/randint.js";
16
+ import { isNumberNode } from "../../../../tree/nodes/numbers/numberNode.js";
17
+ /*
18
+ This toTex() function supports discreteSetNodes with variableNodes inside (this won't create unknown command \\lbracem if m is the first element)
19
+ */
20
+ const discreteSetNodeToTex = (discreteSetNode) => {
21
+ const myCompare = (node1, node2) => {
22
+ if (isNumberNode(node1) && isNumberNode(node2)) {
23
+ return node1.evaluate() - node2.evaluate();
24
+ }
25
+ else if (isNumberNode(node1) && isVariableNode(node2)) {
26
+ return 1;
27
+ }
28
+ else if (isVariableNode(node1) && isNumberNode(node2)) {
29
+ return -1;
30
+ }
31
+ else {
32
+ return node1.toTex().localeCompare(node2.toTex());
33
+ }
34
+ };
35
+ return `\\lbrace ${discreteSetNode.elements
36
+ .toSorted(myCompare)
37
+ .map((node) => node.toTex())
38
+ .join(";")} \\rbrace`;
39
+ };
40
+ const getInstruction = (identifiers) => {
41
+ const { nodeIdsSetA, nodeIdsSetB, isAskedACrossB } = identifiers;
42
+ const [nodeSetA, nodeSetB] = [nodeIdsSetA, nodeIdsSetB].map((nodeIds) => NodeConstructor.fromIdentifiers(nodeIds));
43
+ const texAskedSet = isAskedACrossB ? `A \\times B` : `B \\times A`;
44
+ return `Soient deux ensembles :
45
+
46
+ ${alignTex([
47
+ ["A", nodeSetA],
48
+ ["B", nodeSetB],
49
+ ].map(([letter, nodeSet]) => [letter, "=", discreteSetNodeToTex(nodeSet)]))}
50
+
51
+ Donner le cardinal de $${texAskedSet}$.`;
52
+ };
53
+ const getAnswerNode = (identifiers) => {
54
+ const { nodeIdsSetA, nodeIdsSetB, isAskedACrossB } = identifiers;
55
+ const [nodeSetA, nodeSetB] = [nodeIdsSetA, nodeIdsSetB].map((nodeIds) => NodeConstructor.fromIdentifiers(nodeIds));
56
+ const [nodeSetF, nodeSetS] = isAskedACrossB
57
+ ? [nodeSetA, nodeSetB]
58
+ : [nodeSetB, nodeSetA];
59
+ const [cardF, cardS] = [nodeSetF, nodeSetS].map((discreteSetNode) => discreteSetNode.elements.length);
60
+ const nodeCardinal = multiply(cardF, cardS);
61
+ return nodeCardinal;
62
+ };
63
+ const getAnswer = (identifiers) => {
64
+ return getAnswerNode(identifiers)
65
+ .simplify({ towardsDistribute: true })
66
+ .toTex();
67
+ };
68
+ const getHint = () => {
69
+ return `Le cardinal d'un ensemble fini est le nombre d'éléments de l'ensemble.
70
+
71
+ Soient deux ensembles $C$ et $D$.
72
+ Les éléments de $D \\times C$ sont tous les couples que l'on peut former
73
+ avec comme premier élément un élement de $D$, et comme deuxième élément un élément de $C$.
74
+
75
+ Voici un exemple :
76
+
77
+ $$
78
+ C = \\lbrace 32, 42, 52 \\rbrace
79
+ $$
80
+
81
+ $$
82
+ D = \\lbrace u, v \\rbrace
83
+ $$
84
+
85
+ Voici les couples appartenant à $D \\times C$ :
86
+
87
+ $$
88
+ (u,32),(u,42),(u,52),
89
+ $$
90
+
91
+ $$
92
+ (v,32),(v,42),(v,52)
93
+ $$
94
+
95
+ Le cardinal de $D \\times C$ est donc $2\\times3=6$.`;
96
+ };
97
+ const getCorrection = (identifiers) => {
98
+ const { nodeIdsSetA, nodeIdsSetB, isAskedACrossB } = identifiers;
99
+ const [nodeSetA, nodeSetB] = [nodeIdsSetA, nodeIdsSetB].map((nodeIds) => NodeConstructor.fromIdentifiers(nodeIds));
100
+ const [texSetF, texSetS] = isAskedACrossB ? ["A", "B"] : ["B", "A"];
101
+ const [nodeSetF, nodeSetS] = isAskedACrossB
102
+ ? [nodeSetA, nodeSetB]
103
+ : [nodeSetB, nodeSetA];
104
+ const texAskedSet = `${texSetF} \\times ${texSetS}`;
105
+ const [cardF, cardS] = [nodeSetF, nodeSetS].map((discreteSetNode) => discreteSetNode.elements.length);
106
+ return `Le cardinal d'un ensemble fini est le nombre d'éléments de l'ensemble.
107
+
108
+ ${alignTex([
109
+ [
110
+ `\\text{card}(${texAskedSet})`,
111
+ "=",
112
+ `\\text{card}(${texSetF}) \\times \\text{card}(${texSetS})`,
113
+ ],
114
+ [``, "=", `${cardF.frenchify()} \\times ${cardS.frenchify()}`],
115
+ [``, "=", `${(cardF * cardS).frenchify()}`],
116
+ ])}
117
+
118
+ `;
119
+ };
120
+ const getPropositions = (n, { answer, ...identifiers }) => {
121
+ const { nodeIdsSetA, nodeIdsSetB } = identifiers;
122
+ const [nodeSetA, nodeSetB] = [nodeIdsSetA, nodeIdsSetB].map((nodeIds) => NodeConstructor.fromIdentifiers(nodeIds));
123
+ const [cardA, cardB] = [nodeSetA, nodeSetB].map((discreteSetNode) => discreteSetNode.elements.length);
124
+ const propositions = [];
125
+ addValidProp(propositions, answer);
126
+ tryToAddWrongProp(propositions, "2");
127
+ tryToAddWrongProp(propositions, add(cardA, cardB).simplify({ towardsDistribute: true }).toTex());
128
+ tryToAddWrongProp(propositions, power(cardA, cardB).simplify({ towardsDistribute: true }).toTex());
129
+ tryToAddWrongProp(propositions, power(cardB, cardA).simplify({ towardsDistribute: true }).toTex());
130
+ return shuffleProps(propositions, n);
131
+ };
132
+ const getKeys = () => {
133
+ return [];
134
+ };
135
+ const isAnswerValid = (ans, { answer }) => {
136
+ try {
137
+ return numberVEA(ans, answer);
138
+ }
139
+ catch (err) {
140
+ return handleVEAError(err);
141
+ }
142
+ };
143
+ const getFindCardinalOfCartesianProductOfFiniteSetsQuestion = () => {
144
+ const poolNumberNode = [...Array(20).keys()]
145
+ .map((i) => i * 2)
146
+ .map((v) => v.toTree());
147
+ const poolVarNode1 = ["c", "d", "k"].map((letter) => new VariableNode(letter));
148
+ const poolVarNode2 = ["\\alpha", "\\beta", "\\gamma", "\\delta"].map((letter) => new VariableNode(letter));
149
+ function createRandomSetNode(funcCreateElem, nbElem) {
150
+ const arrNode = shuffle([...Array(nbElem).keys()].reduce((acc, i) => {
151
+ acc = [...acc, funcCreateElem(i, acc)];
152
+ return acc;
153
+ }, []));
154
+ return new DiscreteSetNode(arrNode);
155
+ }
156
+ const nbElemA = randint(2, 10);
157
+ const nbElemB = randint(2, 10, [nbElemA]);
158
+ const poolCommon = [...poolNumberNode, ...poolVarNode1, ...poolVarNode2];
159
+ const poolAOnly = [
160
+ new VariableNode("b"),
161
+ ...[...Array(20).keys()].map((i) => i * 2 + 1).map((v) => v.toTree()),
162
+ ];
163
+ const poolBOnly = ["a", "m", "n"].map((letter) => new VariableNode(letter));
164
+ function* genFuncElemA() {
165
+ yield* shuffle(poolCommon);
166
+ return "Done";
167
+ }
168
+ function* genFuncElemB() {
169
+ yield* shuffle(poolCommon);
170
+ return "Done";
171
+ }
172
+ const [generateElemA, generateElemB] = [genFuncElemA(), genFuncElemB()];
173
+ //ensure A\B is not empty
174
+ const nodeSetA = createRandomSetNode((i) => {
175
+ if (i === nbElemA - 1) {
176
+ return random(poolAOnly);
177
+ }
178
+ else {
179
+ return generateElemA.next().value;
180
+ }
181
+ }, nbElemA);
182
+ //ensure B\A is not empty
183
+ const nodeSetB = createRandomSetNode((i, _arrPrevious) => {
184
+ if (i === nbElemB - 1) {
185
+ return random(poolBOnly);
186
+ }
187
+ else {
188
+ return generateElemB.next().value;
189
+ }
190
+ }, nbElemB);
191
+ const isAskedACrossB = coinFlip();
192
+ const identifiers = {
193
+ nodeIdsSetA: nodeSetA.toIdentifiers(),
194
+ nodeIdsSetB: nodeSetB.toIdentifiers(),
195
+ isAskedACrossB,
196
+ };
197
+ return getQuestionFromIdentifiers(identifiers);
198
+ };
199
+ const getQuestionFromIdentifiers = (identifiers) => {
200
+ const question = {
201
+ instruction: getInstruction(identifiers),
202
+ answer: getAnswer(identifiers),
203
+ keys: getKeys(identifiers),
204
+ answerFormat: "tex",
205
+ identifiers,
206
+ hint: getHint(identifiers),
207
+ correction: getCorrection(identifiers),
208
+ };
209
+ return question;
210
+ };
211
+ export const findCardinalOfCartesianProductOfFiniteSets = {
212
+ id: "findCardinalOfCartesianProductOfFiniteSets",
213
+ connector: "=",
214
+ isSingleStep: true,
215
+ label: "Donner le cardinal du produit cartésien de deux ensembles",
216
+ generator: (nb) => getDistinctQuestions(getFindCardinalOfCartesianProductOfFiniteSetsQuestion, nb),
217
+ qcmTimer: 60,
218
+ freeTimer: 60,
219
+ getPropositions,
220
+ isAnswerValid,
221
+ subject: "Mathématiques",
222
+ hasHintAndCorrection: true,
223
+ getQuestionFromIdentifiers,
224
+ };
@@ -0,0 +1,18 @@
1
+ import { Exercise } from "../../../../exercises/exercise.js";
2
+ import { NodeIdentifiers } from "../../../../tree/nodes/nodeConstructor.js";
3
+ type Situation = {
4
+ strInstruction: string;
5
+ strCorrection: string;
6
+ dictSets: Record<string, {
7
+ cardinal: number;
8
+ strInjected: string;
9
+ strExplain: string;
10
+ }>;
11
+ nodeIdsCardinal: NodeIdentifiers;
12
+ };
13
+ type Identifiers = {
14
+ situation: Situation;
15
+ };
16
+ export declare const findCardinalOfCartesianProductOfFiniteSetsFromSituation: Exercise<Identifiers>;
17
+ export {};
18
+ //# sourceMappingURL=findCardinalOfCartesianProductOfFiniteSetsFromSituation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findCardinalOfCartesianProductOfFiniteSetsFromSituation.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/sets/cartesianProduct/findCardinalOfCartesianProductOfFiniteSetsFromSituation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAgBT,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EAEL,eAAe,EAChB,MAAM,qCAAqC,CAAC;AAuE7C,KAAK,SAAS,GAAG;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CACd,MAAM,EACN;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAC9D,CAAC;IACF,eAAe,EAAE,eAAe,CAAC;CAClC,CAAC;AAqDF,KAAK,WAAW,GAAG;IACjB,SAAS,EAAE,SAAS,CAAC;CACtB,CAAC;AA6IF,eAAO,MAAM,uDAAuD,EAAE,QAAQ,CAAC,WAAW,CAmBvF,CAAC"}
@@ -0,0 +1,198 @@
1
+ import { addValidProp, propWhile, shuffleProps, tryToAddWrongProp, } from "../../../../exercises/exercise.js";
2
+ import { getDistinctQuestions } from "../../../../exercises/utils/getDistinctQuestions.js";
3
+ import { handleVEAError } from "../../../../utils/errors/handleVEAError.js";
4
+ import { NodeConstructor, } from "../../../../tree/nodes/nodeConstructor.js";
5
+ import { random, randomMany } from "../../../../utils/alea/random.js";
6
+ import { coinFlip } from "../../../../utils/alea/coinFlip.js";
7
+ import { multiply } from "../../../../tree/nodes/operators/multiplyNode.js";
8
+ import { numberVEA } from "../../../../exercises/vea/numberVEA.js";
9
+ import { randint } from "../../../../math/utils/random/randint.js";
10
+ import { joinanded } from "../../../../utils/strings/joinanded.js";
11
+ const situationTemplates = [
12
+ {
13
+ strInstruction: "Un coffret contient ${shapes}, ${colors}, et ${sizes}. Combien de perles distinctes existe-t-il ?",
14
+ strCorrection: `\${shapes.explain}
15
+ \${colors.explain}
16
+ \${sizes.explain}
17
+ Le nombre de perles distinctes est donc $\${cardinal}$.`,
18
+ dictFuncs: {
19
+ shapes: () => {
20
+ const pool = ["rondes", "ovales", "carrées", "cylindriques"];
21
+ const cardinal = randint(1, pool.length);
22
+ const arrStr = randomMany(pool, cardinal);
23
+ return {
24
+ cardinal,
25
+ strInjected: `des perles ${joinanded(arrStr, ", ", " et ")}`,
26
+ strExplain: cardinal === 1
27
+ ? `Il y a une seule forme.`
28
+ : `Il y a $${cardinal}$ formes différentes.`,
29
+ };
30
+ },
31
+ colors: () => {
32
+ const pool = ["rouges", "vertes", "bleues", "jaunes"];
33
+ const cardinal = randint(1, pool.length);
34
+ const arrStr = randomMany(pool, cardinal);
35
+ return {
36
+ cardinal,
37
+ strInjected: `des perles ${joinanded(arrStr, ", ", " et ")}`,
38
+ strExplain: cardinal === 1
39
+ ? `Il y a une seule couleur.`
40
+ : `Il y a $${cardinal}$ couleurs différentes.`,
41
+ };
42
+ },
43
+ sizes: () => {
44
+ const cardinal = randint(2, 7);
45
+ return {
46
+ cardinal,
47
+ strInjected: cardinal === 1
48
+ ? `une même taille pour toutes les perles.`
49
+ : `$${cardinal}$ tailles de perles différentes`,
50
+ strExplain: cardinal === 1
51
+ ? `Il y a une seule taille.`
52
+ : `Il y a $${cardinal}$ tailles différentes.`,
53
+ };
54
+ },
55
+ },
56
+ },
57
+ ];
58
+ class SituationConstructor {
59
+ static randomSituationFromTemplate(situationTemplate) {
60
+ const dictSets = Object.entries(situationTemplate.dictFuncs).reduce((acc, [key, func]) => {
61
+ acc[key] = func();
62
+ return acc;
63
+ }, {});
64
+ const { strInstruction, strCorrection: strCorrectionIncomplete, nodeCardinal, } = Object.entries(dictSets).reduce((acc, [key, miniDict]) => {
65
+ acc.strInstruction = acc.strInstruction.replace(`\${${key}}`, miniDict.strInjected);
66
+ acc.strCorrection = acc.strCorrection.replace(`\${${key}.explain}`, miniDict.strExplain);
67
+ acc.nodeCardinal = acc.nodeCardinal
68
+ ? multiply(acc.nodeCardinal, miniDict.cardinal)
69
+ : miniDict.cardinal.toTree();
70
+ return acc;
71
+ }, {
72
+ strInstruction: situationTemplate.strInstruction,
73
+ strCorrection: situationTemplate.strCorrection,
74
+ nodeCardinal: undefined,
75
+ });
76
+ const strCorrection = strCorrectionIncomplete.replace(`\${cardinal}`, `${nodeCardinal.toTex()} = ${nodeCardinal
77
+ .simplify({ towardsDistribute: true })
78
+ .toTex()}`);
79
+ return {
80
+ nodeIdsCardinal: nodeCardinal.toIdentifiers(),
81
+ strInstruction,
82
+ strCorrection,
83
+ dictSets,
84
+ };
85
+ }
86
+ }
87
+ const getInstruction = (identifiers) => {
88
+ const { situation: { strInstruction }, } = identifiers;
89
+ return strInstruction;
90
+ };
91
+ const getAnswerNode = (identifiers) => {
92
+ const { situation: { nodeIdsCardinal }, } = identifiers;
93
+ const nodeCardinal = NodeConstructor.fromIdentifiers(nodeIdsCardinal);
94
+ return nodeCardinal;
95
+ };
96
+ const getAnswer = (identifiers) => {
97
+ return getAnswerNode(identifiers)
98
+ .simplify({ towardsDistribute: true })
99
+ .toTex();
100
+ };
101
+ const getHint = () => {
102
+ return `Le cardinal d'un ensemble fini est le nombre d'éléments de l'ensemble.
103
+
104
+ On va prendre un exemple avec des cartes à jouer.
105
+ Chaque carte peut être soit Valet, soit Dame, soit Roi.
106
+ Chaque carte peut être soit Pique, soit Coeur.
107
+
108
+ Voici toutes les cartes possibles :
109
+
110
+ $$
111
+ (\\text{Valet},\\text{Pique}),(\\text{Valet},\\text{Coeur})
112
+ $$
113
+
114
+ $$
115
+ (\\text{Dame},\\text{Pique}),(\\text{Dame},\\text{Coeur})
116
+ $$
117
+
118
+ $$
119
+ (\\text{Roi},\\text{Pique}),(\\text{Roi},\\text{Coeur})
120
+ $$
121
+
122
+ Il y en a $3\\times2=6$.`;
123
+ };
124
+ const getCorrection = (identifiers) => {
125
+ const { situation: { strCorrection }, } = identifiers;
126
+ return strCorrection;
127
+ };
128
+ const getPropositions = (n, { answer, ...identifiers }) => {
129
+ const { situation: { dictSets }, } = identifiers;
130
+ const propositions = [];
131
+ addValidProp(propositions, answer);
132
+ const arrSubCardinal = Object.values(dictSets).map(({ cardinal }) => cardinal);
133
+ //student: add
134
+ {
135
+ const cardinalWrong = arrSubCardinal.reduce((acc, x) => acc + x, 0);
136
+ tryToAddWrongProp(propositions, cardinalWrong.frenchify());
137
+ }
138
+ //student: max(dictSets.cardinal)
139
+ {
140
+ const cardinalWrong = arrSubCardinal.reduce((acc, x) => Math.max(acc, x), 0);
141
+ tryToAddWrongProp(propositions, cardinalWrong.frenchify());
142
+ }
143
+ propWhile(propositions, n, () => {
144
+ //filler: around answer wrt multiplication tables
145
+ {
146
+ const indexWrong = randint(0, arrSubCardinal.length);
147
+ const arrSubCardinalWrong = arrSubCardinal.map((v, i) => i === indexWrong ? (v === 1 ? v + 1 : v + (coinFlip() ? -1 : 1)) : v);
148
+ const cardinalWrong = arrSubCardinalWrong.reduce((acc, x) => acc * x, 1);
149
+ tryToAddWrongProp(propositions, cardinalWrong.frenchify());
150
+ }
151
+ });
152
+ return shuffleProps(propositions, n);
153
+ };
154
+ const getKeys = () => {
155
+ return [];
156
+ };
157
+ const isAnswerValid = (ans, { answer }) => {
158
+ try {
159
+ return numberVEA(ans, answer);
160
+ }
161
+ catch (err) {
162
+ return handleVEAError(err);
163
+ }
164
+ };
165
+ const getFindCardinalOfCartesianProductOfFiniteSetsFromSituationQuestion = () => {
166
+ const situationTemplate = random(situationTemplates);
167
+ const situation = SituationConstructor.randomSituationFromTemplate(situationTemplate);
168
+ const identifiers = {
169
+ situation,
170
+ };
171
+ return getQuestionFromIdentifiers(identifiers);
172
+ };
173
+ const getQuestionFromIdentifiers = (identifiers) => {
174
+ const question = {
175
+ instruction: getInstruction(identifiers),
176
+ answer: getAnswer(identifiers),
177
+ keys: getKeys(identifiers),
178
+ answerFormat: "tex",
179
+ identifiers,
180
+ hint: getHint(identifiers),
181
+ correction: getCorrection(identifiers),
182
+ };
183
+ return question;
184
+ };
185
+ export const findCardinalOfCartesianProductOfFiniteSetsFromSituation = {
186
+ id: "findCardinalOfCartesianProductOfFiniteSetsFromSituation",
187
+ connector: "=",
188
+ isSingleStep: true,
189
+ label: "Donner le cardinal d'un ensemble produit cartésien défini par une situation",
190
+ generator: (nb) => getDistinctQuestions(getFindCardinalOfCartesianProductOfFiniteSetsFromSituationQuestion, nb),
191
+ qcmTimer: 60,
192
+ freeTimer: 60,
193
+ getPropositions,
194
+ isAnswerValid,
195
+ subject: "Mathématiques",
196
+ hasHintAndCorrection: true,
197
+ getQuestionFromIdentifiers,
198
+ };
@@ -0,0 +1,10 @@
1
+ import { Exercise } from "../../../../exercises/exercise.js";
2
+ import { NodeIdentifiers } from "../../../../tree/nodes/nodeConstructor.js";
3
+ type Identifiers = {
4
+ strDescriptionE: string;
5
+ nodeIdsSetE: NodeIdentifiers;
6
+ k: number;
7
+ };
8
+ export declare const findCardinalOfPowEK: Exercise<Identifiers>;
9
+ export {};
10
+ //# sourceMappingURL=findCardinalOfPowEK.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findCardinalOfPowEK.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/sets/cartesianProduct/findCardinalOfPowEK.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAeT,MAAM,6BAA6B,CAAC;AAIrC,OAAO,EAEL,eAAe,EAChB,MAAM,qCAAqC,CAAC;AAsH7C,KAAK,WAAW,GAAG;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,eAAe,CAAC;IAC7B,CAAC,EAAE,MAAM,CAAC;CACX,CAAC;AAqKF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,WAAW,CAerD,CAAC"}