math-exercises 3.0.199 → 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 (123) 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/combinatory/combination/index.d.ts +3 -0
  22. package/lib/exercises/math/combinatory/combination/index.d.ts.map +1 -0
  23. package/lib/exercises/math/combinatory/combination/index.js +2 -0
  24. package/lib/exercises/math/combinatory/combination/mentalCalculateCombination.d.ts +11 -0
  25. package/lib/exercises/math/combinatory/combination/mentalCalculateCombination.d.ts.map +1 -0
  26. package/lib/exercises/math/combinatory/combination/mentalCalculateCombination.js +225 -0
  27. package/lib/exercises/math/combinatory/combination/writeCombinationFormulaUsingFactorial.d.ts +13 -0
  28. package/lib/exercises/math/combinatory/combination/writeCombinationFormulaUsingFactorial.d.ts.map +1 -0
  29. package/lib/exercises/math/combinatory/combination/writeCombinationFormulaUsingFactorial.js +285 -0
  30. package/lib/exercises/math/dataRepresentations/scatterPlot/scatterPlotInterpreting.d.ts.map +1 -1
  31. package/lib/exercises/math/dataRepresentations/scatterPlot/scatterPlotInterpreting.js +1 -1
  32. package/lib/exercises/math/derivation/derivative/trigo/productOfSinAXPlusBCosCXPlusDDerivative.d.ts +9 -0
  33. package/lib/exercises/math/derivation/derivative/trigo/productOfSinAXPlusBCosCXPlusDDerivative.d.ts.map +1 -0
  34. package/lib/exercises/math/derivation/derivative/trigo/productOfSinAXPlusBCosCXPlusDDerivative.js +209 -0
  35. package/lib/exercises/math/derivation/derivative/trigo/sinAndCosMixedWithSquareDerivative.d.ts +9 -0
  36. package/lib/exercises/math/derivation/derivative/trigo/sinAndCosMixedWithSquareDerivative.d.ts.map +1 -0
  37. package/lib/exercises/math/derivation/derivative/trigo/sinAndCosMixedWithSquareDerivative.js +359 -0
  38. package/lib/exercises/math/derivation/derivative/trigo/sinCosDerivativeRewriteUsingCos2PlusSin2Equals1.d.ts +11 -0
  39. package/lib/exercises/math/derivation/derivative/trigo/sinCosDerivativeRewriteUsingCos2PlusSin2Equals1.d.ts.map +1 -0
  40. package/lib/exercises/math/derivation/derivative/trigo/sinCosDerivativeRewriteUsingCos2PlusSin2Equals1.js +445 -0
  41. package/lib/exercises/math/functions/affines/affineVarTableOnBoundedInterval.d.ts.map +1 -1
  42. package/lib/exercises/math/functions/affines/affineVarTableOnBoundedInterval.js +2 -3
  43. package/lib/exercises/math/index.d.ts +1 -0
  44. package/lib/exercises/math/index.d.ts.map +1 -1
  45. package/lib/exercises/math/index.js +1 -1
  46. package/lib/exercises/math/limits/sequenceGeometricLimit.d.ts.map +1 -1
  47. package/lib/exercises/math/limits/sequenceGeometricLimit.js +9 -0
  48. package/lib/exercises/math/primitive/constantPrimitive.d.ts +8 -5
  49. package/lib/exercises/math/primitive/constantPrimitive.d.ts.map +1 -1
  50. package/lib/exercises/math/primitive/constantPrimitive.js +40 -21
  51. package/lib/exercises/math/probaStat/stats2var/averagePoint.d.ts.map +1 -1
  52. package/lib/exercises/math/probaStat/stats2var/averagePoint.js +34 -2
  53. package/lib/exercises/math/sequences/geometric/graph/geometricFindThresholdFromGraph.d.ts +15 -0
  54. package/lib/exercises/math/sequences/geometric/graph/geometricFindThresholdFromGraph.d.ts.map +1 -0
  55. package/lib/exercises/math/sequences/geometric/graph/geometricFindThresholdFromGraph.js +255 -0
  56. package/lib/exercises/math/sequences/geometric/graph/geometricFindThresholdUsingCalculator.d.ts +15 -0
  57. package/lib/exercises/math/sequences/geometric/graph/geometricFindThresholdUsingCalculator.d.ts.map +1 -0
  58. package/lib/exercises/math/sequences/geometric/graph/geometricFindThresholdUsingCalculator.js +242 -0
  59. package/lib/exercises/math/sequences/geometric/graph/geometricPlaceFirstPoints.js +4 -4
  60. package/lib/exercises/math/sequences/geometric/graph/geometricSignOfReasonFromGraph.d.ts +12 -0
  61. package/lib/exercises/math/sequences/geometric/graph/geometricSignOfReasonFromGraph.d.ts.map +1 -0
  62. package/lib/exercises/math/sequences/geometric/graph/geometricSignOfReasonFromGraph.js +161 -0
  63. package/lib/exercises/math/sets/cartesianProduct/findCardinalOfCartesianProductOfFiniteSets.d.ts +10 -0
  64. package/lib/exercises/math/sets/cartesianProduct/findCardinalOfCartesianProductOfFiniteSets.d.ts.map +1 -0
  65. package/lib/exercises/math/sets/cartesianProduct/findCardinalOfCartesianProductOfFiniteSets.js +224 -0
  66. package/lib/exercises/math/sets/cartesianProduct/findCardinalOfCartesianProductOfFiniteSetsFromSituation.d.ts +18 -0
  67. package/lib/exercises/math/sets/cartesianProduct/findCardinalOfCartesianProductOfFiniteSetsFromSituation.d.ts.map +1 -0
  68. package/lib/exercises/math/sets/cartesianProduct/findCardinalOfCartesianProductOfFiniteSetsFromSituation.js +198 -0
  69. package/lib/exercises/math/sets/cartesianProduct/findCardinalOfPowEK.d.ts +10 -0
  70. package/lib/exercises/math/sets/cartesianProduct/findCardinalOfPowEK.d.ts.map +1 -0
  71. package/lib/exercises/math/sets/cartesianProduct/findCardinalOfPowEK.js +231 -0
  72. package/lib/exercises/math/sets/cartesianProduct/findNumberOfPasswordsWithLettersAndNumbers.d.ts +19 -0
  73. package/lib/exercises/math/sets/cartesianProduct/findNumberOfPasswordsWithLettersAndNumbers.d.ts.map +1 -0
  74. package/lib/exercises/math/sets/cartesianProduct/findNumberOfPasswordsWithLettersAndNumbers.js +187 -0
  75. package/lib/exercises/math/sets/cartesianProduct/index.d.ts +7 -0
  76. package/lib/exercises/math/sets/cartesianProduct/index.d.ts.map +1 -0
  77. package/lib/exercises/math/sets/cartesianProduct/index.js +6 -0
  78. package/lib/exercises/math/sets/cartesianProduct/proposeElementInCartesianProductOfFiniteSets.d.ts +15 -0
  79. package/lib/exercises/math/sets/cartesianProduct/proposeElementInCartesianProductOfFiniteSets.d.ts.map +1 -0
  80. package/lib/exercises/math/sets/cartesianProduct/proposeElementInCartesianProductOfFiniteSets.js +291 -0
  81. package/lib/exercises/math/sets/cartesianProduct/proposeElementInPowEK.d.ts +15 -0
  82. package/lib/exercises/math/sets/cartesianProduct/proposeElementInPowEK.d.ts.map +1 -0
  83. package/lib/exercises/math/sets/cartesianProduct/proposeElementInPowEK.js +274 -0
  84. package/lib/exercises/math/sets/combinations/findNumberOfCombinationsFromSituation.d.ts +17 -0
  85. package/lib/exercises/math/sets/combinations/findNumberOfCombinationsFromSituation.d.ts.map +1 -0
  86. package/lib/exercises/math/sets/combinations/findNumberOfCombinationsFromSituation.js +228 -0
  87. package/lib/exercises/math/sets/combinations/findNumberOfProductsOfCombinationsFromSituation.d.ts +17 -0
  88. package/lib/exercises/math/sets/combinations/findNumberOfProductsOfCombinationsFromSituation.d.ts.map +1 -0
  89. package/lib/exercises/math/sets/combinations/findNumberOfProductsOfCombinationsFromSituation.js +388 -0
  90. package/lib/exercises/math/sets/combinations/index.d.ts +4 -0
  91. package/lib/exercises/math/sets/combinations/index.d.ts.map +1 -0
  92. package/lib/exercises/math/sets/combinations/index.js +3 -0
  93. package/lib/exercises/math/sets/combinations/proposeCombination.d.ts +15 -0
  94. package/lib/exercises/math/sets/combinations/proposeCombination.d.ts.map +1 -0
  95. package/lib/exercises/math/sets/combinations/proposeCombination.js +347 -0
  96. package/lib/exercises/math/sets/partialPermutations/findNumberOfPartialPermutationsFromSituation.d.ts +16 -0
  97. package/lib/exercises/math/sets/partialPermutations/findNumberOfPartialPermutationsFromSituation.d.ts.map +1 -0
  98. package/lib/exercises/math/sets/partialPermutations/findNumberOfPartialPermutationsFromSituation.js +186 -0
  99. package/lib/exercises/math/sets/partialPermutations/findNumberOfPermutationsFromSituation.d.ts +17 -0
  100. package/lib/exercises/math/sets/partialPermutations/findNumberOfPermutationsFromSituation.d.ts.map +1 -0
  101. package/lib/exercises/math/sets/partialPermutations/findNumberOfPermutationsFromSituation.js +232 -0
  102. package/lib/exercises/math/sets/partialPermutations/index.d.ts +4 -0
  103. package/lib/exercises/math/sets/partialPermutations/index.d.ts.map +1 -0
  104. package/lib/exercises/math/sets/partialPermutations/index.js +3 -0
  105. package/lib/exercises/math/sets/partialPermutations/proposePartialPermutation.d.ts +15 -0
  106. package/lib/exercises/math/sets/partialPermutations/proposePartialPermutation.d.ts.map +1 -0
  107. package/lib/exercises/math/sets/partialPermutations/proposePartialPermutation.js +343 -0
  108. package/lib/exercises/math/trigonometry/functions/parityOfCosAXTimesSinBX.d.ts +8 -0
  109. package/lib/exercises/math/trigonometry/functions/parityOfCosAXTimesSinBX.d.ts.map +1 -0
  110. package/lib/exercises/math/trigonometry/functions/parityOfCosAXTimesSinBX.js +193 -0
  111. package/lib/index.d.ts +15 -1
  112. package/lib/index.d.ts.map +1 -1
  113. package/lib/math/sets/setOperations.d.ts +9 -0
  114. package/lib/math/sets/setOperations.d.ts.map +1 -0
  115. package/lib/math/sets/setOperations.js +84 -0
  116. package/lib/math/sets/tuple.d.ts +12 -0
  117. package/lib/math/sets/tuple.d.ts.map +1 -0
  118. package/lib/math/sets/tuple.js +17 -0
  119. package/lib/server.js +25 -0
  120. package/lib/tree/utilities/nodePrinter.d.ts +7 -0
  121. package/lib/tree/utilities/nodePrinter.d.ts.map +1 -0
  122. package/lib/tree/utilities/nodePrinter.js +36 -0
  123. package/package.json +1 -1
@@ -0,0 +1,231 @@
1
+ import { addValidProp, shuffleProps, tryToAddWrongProp, } from "../../../../exercises/exercise.js";
2
+ import { getDistinctQuestions } from "../../../../exercises/utils/getDistinctQuestions.js";
3
+ import { parseAlgebraic } from "../../../../tree/parsers/latexParser.js";
4
+ import { handleVEAError } from "../../../../utils/errors/handleVEAError.js";
5
+ import { NodeConstructor, } from "../../../../tree/nodes/nodeConstructor.js";
6
+ import { DiscreteSetNode } from "../../../../tree/nodes/sets/discreteSetNode.js";
7
+ import { isVariableNode, VariableNode, } from "../../../../tree/nodes/variables/variableNode.js";
8
+ import { NodeComparator } from "../../../../tree/utilities/nodeComparator.js";
9
+ import { randint } from "../../../../math/utils/random/randint.js";
10
+ import { shuffle } from "../../../../utils/alea/shuffle.js";
11
+ import { coinFlip } from "../../../../utils/alea/coinFlip.js";
12
+ import { probaLawFlip } from "../../../../utils/alea/probaLawFlip.js";
13
+ import { randomMany } from "../../../../utils/alea/random.js";
14
+ import { power } from "../../../../tree/nodes/operators/powerNode.js";
15
+ import { multiply } from "../../../../tree/nodes/operators/multiplyNode.js";
16
+ import { facto } from "../../../../tree/nodes/functions/factorialNode.js";
17
+ const randomDiscreteSetIdsAndDescription = () => {
18
+ return probaLawFlip([
19
+ [
20
+ (() => {
21
+ const nbElements = randint(2, 5);
22
+ const arrLetter = shuffle(["a", "b", "c", "d"]).slice(0, nbElements);
23
+ const arrNode = arrLetter.map((letter) => new VariableNode(letter));
24
+ const nodeSetE = new DiscreteSetNode(arrNode);
25
+ return {
26
+ nodeIdsSetE: nodeSetE.toIdentifiers(),
27
+ strDescriptionE: `l'ensemble $${discreteSetNodeToTex(nodeSetE)}$`,
28
+ };
29
+ })(),
30
+ 0.3,
31
+ ],
32
+ [
33
+ (() => {
34
+ const nbElements = randint(2, 6);
35
+ const arrNumber = randomMany([...Array(9).keys()].map((i) => i + 1), nbElements);
36
+ const arrNode = shuffle(arrNumber.map((v) => v.toTree()));
37
+ const nodeSetE = new DiscreteSetNode(arrNode);
38
+ return {
39
+ nodeIdsSetE: nodeSetE.toIdentifiers(),
40
+ strDescriptionE: `l'ensemble $${discreteSetNodeToTex(nodeSetE)}$`,
41
+ };
42
+ })(),
43
+ 0.3,
44
+ ],
45
+ [
46
+ (() => {
47
+ const [boundLowRaw, boundHighRaw] = [randint(2, 8), randint(13, 19)];
48
+ const [isBoundLowIncluded, isBoundHighIncluded] = [0, 1].map(() => coinFlip());
49
+ const boundLow = boundLowRaw + (isBoundLowIncluded ? 0 : 1);
50
+ const boundHigh = boundHighRaw + (isBoundHighIncluded ? 0 : -1);
51
+ const arrNumber = [...Array(boundHigh - boundLow).keys()].map((i) => i + boundLow);
52
+ const arrNode = arrNumber.map((v) => v.toTree());
53
+ const nodeSetE = new DiscreteSetNode(arrNode);
54
+ return {
55
+ nodeIdsSetE: nodeSetE.toIdentifiers(),
56
+ strDescriptionE: `l'ensemble des entiers compris entre $${boundLow}$ ${isBoundLowIncluded ? "inclus" : "exclu"} et $${boundHigh}$ ${isBoundHighIncluded ? "inclus" : "exclu"}`,
57
+ };
58
+ })(),
59
+ 0.2,
60
+ ],
61
+ [
62
+ (() => {
63
+ const isFilterEven = coinFlip();
64
+ const [boundLowRaw, boundHighRaw] = [randint(2, 8), randint(13, 19)];
65
+ const [isBoundLowIncluded, isBoundHighIncluded] = [0, 1].map(() => coinFlip());
66
+ const boundLow = boundLowRaw + (isBoundLowIncluded ? 0 : 1);
67
+ const boundHigh = boundHighRaw + (isBoundHighIncluded ? 0 : -1);
68
+ const arrNumber = [...Array(boundHigh - boundLow).keys()]
69
+ .map((i) => i + boundLow)
70
+ .filter((v) => (isFilterEven ? v % 2 === 0 : v % 2 === 1));
71
+ const arrNode = arrNumber.map((v) => v.toTree());
72
+ const nodeSetE = new DiscreteSetNode(arrNode);
73
+ return {
74
+ nodeIdsSetE: nodeSetE.toIdentifiers(),
75
+ strDescriptionE: `l'ensemble des entiers ${isFilterEven ? "pairs" : "impairs"} compris entre $${boundLow}$ ${isBoundLowIncluded ? "inclus" : "exclu"} et $${boundHigh}$ ${isBoundHighIncluded ? "inclus" : "exclu"}`,
76
+ };
77
+ })(),
78
+ 0.2,
79
+ ],
80
+ ]);
81
+ };
82
+ /*
83
+ This toTex() function supports discreteSetNodes with variableNodes inside (this won't create unknown command \\lbracem if m is the first element)
84
+ */
85
+ const discreteSetNodeToTex = (discreteSetNode) => {
86
+ return `\\lbrace ${discreteSetNode.elements
87
+ .map((el) => el.toTex())
88
+ .join(";")} \\rbrace`;
89
+ };
90
+ const getInstruction = (identifiers) => {
91
+ const { strDescriptionE, k } = identifiers;
92
+ return `Soit $E$ ${strDescriptionE}.
93
+ Donner le nombre de $${k}$-uplets d'éléments de E.`;
94
+ };
95
+ const getAnswerNode = (identifiers) => {
96
+ const { nodeIdsSetE, k } = identifiers;
97
+ const nodeSetE = NodeConstructor.fromIdentifiers(nodeIdsSetE);
98
+ return power(nodeSetE.elements.length, k);
99
+ };
100
+ const getAnswer = (identifiers) => {
101
+ return getAnswerNode(identifiers).toTex();
102
+ };
103
+ const getHint = (identifiers) => {
104
+ const { k } = identifiers;
105
+ return `Pour prendre un $${k}$-uplet au hasard, tu peux effectuer $${k}$ tirages avec remise d'un élement de $E$.
106
+ Combien y a-t-il d'issues pour un tirage ?
107
+ Combien y a-t-il de séquences différentes de $${k}$ tirages ?`;
108
+ };
109
+ const getCorrection = (identifiers) => {
110
+ const { nodeIdsSetE, k } = identifiers;
111
+ const nodeSetE = NodeConstructor.fromIdentifiers(nodeIdsSetE);
112
+ const nbElements = nodeSetE.elements.length;
113
+ return `
114
+ $$
115
+ E = ${discreteSetNodeToTex(nodeSetE)}
116
+ $$
117
+
118
+ $E$ comporte $${nbElements}$ éléments.
119
+
120
+ Si on prend un $${k}$-uplet au hasard,
121
+ il y a $${nbElements}$ possibilités pour la première composante,
122
+ il y a $${nbElements}$ possibilités pour la deuxième composante,
123
+ etc.
124
+
125
+ Le nombre de $${k}$-uplets d'éléments de $E$ est $${getAnswer(identifiers)}$.`;
126
+ };
127
+ const getPropositions = (n, { answer, ...identifiers }) => {
128
+ const { nodeIdsSetE, k } = identifiers;
129
+ const nodeSetE = NodeConstructor.fromIdentifiers(nodeIdsSetE);
130
+ const nbElements = nodeSetE.elements.length;
131
+ const propositions = [];
132
+ addValidProp(propositions, answer);
133
+ //student: k^card(E)
134
+ {
135
+ const node = power(k, nbElements);
136
+ tryToAddWrongProp(propositions, node.toTex());
137
+ }
138
+ //student: nb of k-uples of distinct elements of E
139
+ {
140
+ if (k <= nbElements) {
141
+ const node = [...Array(k).keys()]
142
+ .map((i) => i + (nbElements - k + 1))
143
+ .toReversed()
144
+ .map((v) => v.toTree())
145
+ .reduce((acc, x) => multiply(acc, x));
146
+ tryToAddWrongProp(propositions, node.toTex());
147
+ }
148
+ }
149
+ //student: k * card(E)
150
+ {
151
+ const node = multiply(k, nbElements);
152
+ tryToAddWrongProp(propositions, node.toTex());
153
+ }
154
+ //student: (k*card(E))!
155
+ {
156
+ const node = facto(multiply(k, nbElements));
157
+ tryToAddWrongProp(propositions, node.toTex());
158
+ }
159
+ return shuffleProps(propositions, n);
160
+ };
161
+ const getKeys = (identifiers) => {
162
+ const { nodeIdsSetE } = identifiers;
163
+ const nodeSetE = NodeConstructor.fromIdentifiers(nodeIdsSetE);
164
+ const arrVarNode = nodeSetE.elements.filter((node) => isVariableNode(node));
165
+ return [
166
+ "semicolon",
167
+ "lbrace", //pas gentil
168
+ "rbrace", //pas gentil
169
+ ...arrVarNode.map((varNode) => {
170
+ const tex = varNode.toTex();
171
+ return {
172
+ id: "custom",
173
+ label: tex,
174
+ labelType: "tex",
175
+ mathfieldInstructions: {
176
+ method: "write",
177
+ content: tex,
178
+ },
179
+ };
180
+ }),
181
+ ];
182
+ };
183
+ const isAnswerValid = (ans, { answer, ..._identifiers }) => {
184
+ try {
185
+ const nodeAns = parseAlgebraic(ans);
186
+ const nodeAnswer = parseAlgebraic(answer);
187
+ return (NodeComparator.isEqualViaSub(nodeAns, nodeAnswer) ||
188
+ NodeComparator.isEqualViaFrac(nodeAns, nodeAnswer));
189
+ }
190
+ catch (e) {
191
+ handleVEAError(e);
192
+ return false;
193
+ }
194
+ };
195
+ const getFindCardinalOfPowEKQuestion = () => {
196
+ const k = randint(3, 6);
197
+ const dict = randomDiscreteSetIdsAndDescription();
198
+ const nodeSetE = NodeConstructor.fromIdentifiers(dict.nodeIdsSetE);
199
+ const identifiers = {
200
+ strDescriptionE: dict.strDescriptionE,
201
+ nodeIdsSetE: nodeSetE.toIdentifiers(),
202
+ k,
203
+ };
204
+ return getQuestionFromIdentifiers(identifiers);
205
+ };
206
+ const getQuestionFromIdentifiers = (identifiers) => {
207
+ const question = {
208
+ instruction: getInstruction(identifiers),
209
+ answer: getAnswer(identifiers),
210
+ keys: getKeys(identifiers),
211
+ answerFormat: "tex",
212
+ identifiers,
213
+ hint: getHint(identifiers),
214
+ correction: getCorrection(identifiers),
215
+ };
216
+ return question;
217
+ };
218
+ export const findCardinalOfPowEK = {
219
+ id: "findCardinalOfPowEK",
220
+ connector: "=",
221
+ isSingleStep: true,
222
+ label: "Un ensemble $E$ étant donné, donner le nombre de $k$-uplets d'éléments de $E$",
223
+ generator: (nb) => getDistinctQuestions(getFindCardinalOfPowEKQuestion, nb),
224
+ qcmTimer: 60,
225
+ freeTimer: 60,
226
+ getPropositions,
227
+ isAnswerValid,
228
+ subject: "Mathématiques",
229
+ hasHintAndCorrection: true,
230
+ getQuestionFromIdentifiers,
231
+ };
@@ -0,0 +1,19 @@
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
+ arrSets: {
7
+ cardinal: number;
8
+ nbSamples: number;
9
+ strInjected: string;
10
+ strExplain: string;
11
+ }[];
12
+ nodeIdsCardinal: NodeIdentifiers;
13
+ };
14
+ type Identifiers = {
15
+ situation: Situation;
16
+ };
17
+ export declare const findNumberOfPasswordsWithLettersAndNumbers: Exercise<Identifiers>;
18
+ export {};
19
+ //# sourceMappingURL=findNumberOfPasswordsWithLettersAndNumbers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findNumberOfPasswordsWithLettersAndNumbers.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/sets/cartesianProduct/findNumberOfPasswordsWithLettersAndNumbers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAeT,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EAEL,eAAe,EAChB,MAAM,qCAAqC,CAAC;AA4E7C,KAAK,SAAS,GAAG;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE;QACP,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,EAAE,MAAM,CAAC;QACpB,UAAU,EAAE,MAAM,CAAC;KACpB,EAAE,CAAC;IACJ,eAAe,EAAE,eAAe,CAAC;CAClC,CAAC;AA+DF,KAAK,WAAW,GAAG;IACjB,SAAS,EAAE,SAAS,CAAC;CACtB,CAAC;AA2IF,eAAO,MAAM,0CAA0C,EAAE,QAAQ,CAAC,WAAW,CAmB1E,CAAC"}
@@ -0,0 +1,187 @@
1
+ import { addValidProp, 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 { multiply } from "../../../../tree/nodes/operators/multiplyNode.js";
7
+ import { randint } from "../../../../math/utils/random/randint.js";
8
+ import { joinanded } from "../../../../utils/strings/joinanded.js";
9
+ import { shuffle } from "../../../../utils/alea/shuffle.js";
10
+ import { zip } from "../../../../utils/arrays/arrayZip.js";
11
+ import { power } from "../../../../tree/nodes/operators/powerNode.js";
12
+ import { add } from "../../../../tree/nodes/operators/addNode.js";
13
+ import { parseAlgebraic } from "../../../../tree/parsers/latexParser.js";
14
+ import { NodeComparator } from "../../../../tree/utilities/nodeComparator.js";
15
+ const situationTemplates = [
16
+ {
17
+ strInstruction: "Combien existe-t-il de mots de passe constitués de ${req1} puis de ${req2} ?",
18
+ strCorrection: `\${req1.explain}
19
+ \${req2.explain}
20
+ Le nombre de mots de passe différents est donc $\${cardinal}$.`,
21
+ dictFuncs: {
22
+ letters: (nbSamples) => {
23
+ const cardinal = 26;
24
+ return {
25
+ cardinal,
26
+ nbSamples,
27
+ strInjected: `$${nbSamples}$ lettres`,
28
+ strExplain: `Il y a $${cardinal}$ lettres possibles.`,
29
+ };
30
+ },
31
+ digits: (nbSamples) => {
32
+ const cardinal = 10;
33
+ return {
34
+ cardinal,
35
+ nbSamples,
36
+ strInjected: `$${nbSamples}$ chiffres`,
37
+ strExplain: `Il y a $${cardinal}$ chiffres possibles (${joinanded("0123456789".split("").map((str) => `$${str}$`), ", ", " et ")}).`,
38
+ };
39
+ },
40
+ special: (nbSamples) => {
41
+ const pool = ["!", "@", "*", "&", "?"];
42
+ const cardinal = randint(3, pool.length + 1);
43
+ const arrStr = randomMany(pool, cardinal);
44
+ return {
45
+ cardinal,
46
+ nbSamples,
47
+ strInjected: `$${nbSamples}$ caractères spéciaux (on se limite aux caractères ${joinanded(arrStr, " ", " ")})`,
48
+ strExplain: `Il y a $${cardinal}$ caractères spéciaux possibles.`,
49
+ };
50
+ },
51
+ },
52
+ },
53
+ ];
54
+ class SituationConstructor {
55
+ static randomSituationFromTemplate(situationTemplate) {
56
+ const arrNb = [randint(3, 8), randint(3, 8)];
57
+ const arrSets = zip(arrNb, shuffle(Object.values(situationTemplate.dictFuncs)).slice(arrNb.length - 1)).map(([nb, func]) => func(nb));
58
+ const { strInstruction, strCorrection: strCorrectionIncomplete, nodeCardinal, nodeCardinalExpanded, } = arrSets.reduce((acc, miniDict, i) => {
59
+ const index = i + 1;
60
+ acc.strInstruction = acc.strInstruction.replace(`\${req${index}}`, miniDict.strInjected);
61
+ acc.strCorrection = acc.strCorrection.replace(`\${req${index}.explain}`, miniDict.strExplain);
62
+ acc.nodeCardinal = acc.nodeCardinal
63
+ ? multiply(acc.nodeCardinal, power(miniDict.cardinal, miniDict.nbSamples))
64
+ : power(miniDict.cardinal, miniDict.nbSamples);
65
+ acc.nodeCardinalExpanded = acc.nodeCardinalExpanded
66
+ ? multiply(acc.nodeCardinalExpanded, power(miniDict.cardinal, miniDict.nbSamples).toMultiplyNode())
67
+ : power(miniDict.cardinal, miniDict.nbSamples).toMultiplyNode();
68
+ return acc;
69
+ }, {
70
+ strInstruction: situationTemplate.strInstruction,
71
+ strCorrection: situationTemplate.strCorrection,
72
+ nodeCardinal: undefined,
73
+ nodeCardinalExpanded: undefined,
74
+ });
75
+ const strCorrection = strCorrectionIncomplete.replace(`\${cardinal}`, `${nodeCardinalExpanded.toTex()} = ${nodeCardinal.toTex()}`);
76
+ return {
77
+ nodeIdsCardinal: nodeCardinal.toIdentifiers(),
78
+ strInstruction,
79
+ strCorrection,
80
+ arrSets,
81
+ };
82
+ }
83
+ }
84
+ const getInstruction = (identifiers) => {
85
+ const { situation: { strInstruction }, } = identifiers;
86
+ return strInstruction;
87
+ };
88
+ const getAnswerNode = (identifiers) => {
89
+ const { situation: { nodeIdsCardinal }, } = identifiers;
90
+ const nodeCardinal = NodeConstructor.fromIdentifiers(nodeIdsCardinal);
91
+ return nodeCardinal;
92
+ };
93
+ const getAnswer = (identifiers) => {
94
+ return getAnswerNode(identifiers)
95
+ .simplify({ towardsDistribute: true })
96
+ .toTex();
97
+ };
98
+ const getHint = () => {
99
+ return `Voici un exemple avec un mot de passe de longueur $3$ constitué uniquement avec les lettres a, b, c ou d.
100
+ Il y a $4$ possibilités pour le premier caractère.
101
+ Il y a $4$ possibilités pour le deuxième caractère.
102
+ Il y a $4$ possibilités pour le troisième caractère.
103
+ Il y a donc en tout $4 \\times 4 \\times 4 = 4^3$ mots de passe possibles.`;
104
+ };
105
+ const getCorrection = (identifiers) => {
106
+ const { situation: { strCorrection }, } = identifiers;
107
+ return strCorrection;
108
+ };
109
+ const getPropositions = (n, { answer, ...identifiers }) => {
110
+ const { situation: { arrSets }, } = identifiers;
111
+ const propositions = [];
112
+ addValidProp(propositions, answer);
113
+ //student: multiplies everything
114
+ {
115
+ const nodeWrong = arrSets.slice(1).reduce((acc, { cardinal, nbSamples }) => multiply(acc, multiply(cardinal, nbSamples)), (() => {
116
+ const { cardinal, nbSamples } = arrSets[0];
117
+ return multiply(cardinal, nbSamples);
118
+ })());
119
+ tryToAddWrongProp(propositions, nodeWrong.toTex());
120
+ }
121
+ //student: times+times+times
122
+ {
123
+ const nodeWrong = arrSets.slice(1).reduce((acc, { cardinal, nbSamples }) => add(acc, multiply(cardinal, nbSamples)), (() => {
124
+ const { cardinal, nbSamples } = arrSets[0];
125
+ return multiply(cardinal, nbSamples);
126
+ })());
127
+ tryToAddWrongProp(propositions, nodeWrong.toTex());
128
+ }
129
+ //student: pow+pow+pow
130
+ {
131
+ const nodeWrong = arrSets.slice(1).reduce((acc, { cardinal, nbSamples }) => add(acc, power(cardinal, nbSamples)), (() => {
132
+ const { cardinal, nbSamples } = arrSets[0];
133
+ return power(cardinal, nbSamples);
134
+ })());
135
+ tryToAddWrongProp(propositions, nodeWrong.toTex());
136
+ }
137
+ return shuffleProps(propositions, n);
138
+ };
139
+ const getKeys = () => {
140
+ return [];
141
+ };
142
+ const isAnswerValid = (ans, { answer, ..._identifiers }) => {
143
+ try {
144
+ const nodeAns = parseAlgebraic(ans);
145
+ const nodeAnswer = parseAlgebraic(answer);
146
+ return (NodeComparator.isEqualViaFrac(nodeAns, nodeAnswer) ||
147
+ NodeComparator.isEqualViaSub(nodeAns, nodeAnswer));
148
+ }
149
+ catch (e) {
150
+ handleVEAError(e);
151
+ return false;
152
+ }
153
+ };
154
+ const getFindNumberOfPasswordsWithLettersAndNumbersQuestion = () => {
155
+ const situationTemplate = random(situationTemplates);
156
+ const situation = SituationConstructor.randomSituationFromTemplate(situationTemplate);
157
+ const identifiers = {
158
+ situation,
159
+ };
160
+ return getQuestionFromIdentifiers(identifiers);
161
+ };
162
+ const getQuestionFromIdentifiers = (identifiers) => {
163
+ const question = {
164
+ instruction: getInstruction(identifiers),
165
+ answer: getAnswer(identifiers),
166
+ keys: getKeys(identifiers),
167
+ answerFormat: "tex",
168
+ identifiers,
169
+ hint: getHint(identifiers),
170
+ correction: getCorrection(identifiers),
171
+ };
172
+ return question;
173
+ };
174
+ export const findNumberOfPasswordsWithLettersAndNumbers = {
175
+ id: "findNumberOfPasswordsWithLettersAndNumbers",
176
+ connector: "=",
177
+ isSingleStep: true,
178
+ label: "Déterminer le nombre de mots de passe possibles (avec $2$ types de caractères)",
179
+ generator: (nb) => getDistinctQuestions(getFindNumberOfPasswordsWithLettersAndNumbersQuestion, nb),
180
+ qcmTimer: 60,
181
+ freeTimer: 60,
182
+ getPropositions,
183
+ isAnswerValid,
184
+ subject: "Mathématiques",
185
+ hasHintAndCorrection: true,
186
+ getQuestionFromIdentifiers,
187
+ };
@@ -0,0 +1,7 @@
1
+ export * from "./proposeElementInCartesianProductOfFiniteSets.js";
2
+ export * from "./findCardinalOfCartesianProductOfFiniteSets.js";
3
+ export * from "./findCardinalOfCartesianProductOfFiniteSetsFromSituation.js";
4
+ export * from "./proposeElementInPowEK.js";
5
+ export * from "./findCardinalOfPowEK.js";
6
+ export * from "./findNumberOfPasswordsWithLettersAndNumbers.js";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/sets/cartesianProduct/index.ts"],"names":[],"mappings":"AAAA,cAAc,mDAAmD,CAAC;AAClE,cAAc,iDAAiD,CAAC;AAChE,cAAc,8DAA8D,CAAC;AAC7E,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,iDAAiD,CAAC"}
@@ -0,0 +1,6 @@
1
+ export * from "./proposeElementInCartesianProductOfFiniteSets.js";
2
+ export * from "./findCardinalOfCartesianProductOfFiniteSets.js";
3
+ export * from "./findCardinalOfCartesianProductOfFiniteSetsFromSituation.js";
4
+ export * from "./proposeElementInPowEK.js";
5
+ export * from "./findCardinalOfPowEK.js";
6
+ export * from "./findNumberOfPasswordsWithLettersAndNumbers.js";
@@ -0,0 +1,15 @@
1
+ import { Exercise } from "../../../../exercises/exercise.js";
2
+ import { NodeIdentifiers } from "../../../../tree/nodes/nodeConstructor.js";
3
+ type Item = {
4
+ tex: string;
5
+ isValid: boolean;
6
+ };
7
+ type Identifiers = {
8
+ nodeIdsSetA: NodeIdentifiers;
9
+ nodeIdsSetB: NodeIdentifiers;
10
+ isAskedACrossB: boolean;
11
+ items: Item[];
12
+ };
13
+ export declare const proposeElementInCartesianProductOfFiniteSets: Exercise<Identifiers>;
14
+ export {};
15
+ //# sourceMappingURL=proposeElementInCartesianProductOfFiniteSets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proposeElementInCartesianProductOfFiniteSets.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/sets/cartesianProduct/proposeElementInCartesianProductOfFiniteSets.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAeT,MAAM,6BAA6B,CAAC;AAMrC,OAAO,EAEL,eAAe,EAChB,MAAM,qCAAqC,CAAC;AA2B7C,KAAK,IAAI,GAAG;IACV,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,KAAK,WAAW,GAAG;IACjB,WAAW,EAAE,eAAe,CAAC;IAC7B,WAAW,EAAE,eAAe,CAAC;IAC7B,cAAc,EAAE,OAAO,CAAC;IACxB,KAAK,EAAE,IAAI,EAAE,CAAC;CACf,CAAC;AAwUF,eAAO,MAAM,4CAA4C,EAAE,QAAQ,CAAC,WAAW,CAmB5E,CAAC"}