math-exercises 3.0.185 → 3.0.186

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 (66) hide show
  1. package/lib/exercises/exercise.d.ts +1 -0
  2. package/lib/exercises/exercise.d.ts.map +1 -1
  3. package/lib/exercises/math/derivation/derivative/exp/index.d.ts +2 -0
  4. package/lib/exercises/math/derivation/derivative/exp/index.d.ts.map +1 -1
  5. package/lib/exercises/math/derivation/derivative/exp/index.js +2 -0
  6. package/lib/exercises/math/derivation/derivative/index.d.ts +3 -0
  7. package/lib/exercises/math/derivation/derivative/index.d.ts.map +1 -1
  8. package/lib/exercises/math/derivation/derivative/index.js +3 -0
  9. package/lib/exercises/math/derivation/derivativeNumber/index.d.ts +2 -0
  10. package/lib/exercises/math/derivation/derivativeNumber/index.d.ts.map +1 -1
  11. package/lib/exercises/math/derivation/derivativeNumber/index.js +2 -0
  12. package/lib/exercises/math/derivation/index.d.ts +1 -0
  13. package/lib/exercises/math/derivation/index.d.ts.map +1 -1
  14. package/lib/exercises/math/derivation/index.js +1 -0
  15. package/lib/exercises/math/derivation/tangent/index.d.ts +9 -0
  16. package/lib/exercises/math/derivation/tangent/index.d.ts.map +1 -1
  17. package/lib/exercises/math/derivation/tangent/index.js +9 -0
  18. package/lib/exercises/math/derivation/variations/index.d.ts +8 -0
  19. package/lib/exercises/math/derivation/variations/index.d.ts.map +1 -1
  20. package/lib/exercises/math/derivation/variations/index.js +8 -0
  21. package/lib/exercises/math/derivation/variations/signVarTable3dDegree.d.ts +10 -0
  22. package/lib/exercises/math/derivation/variations/signVarTable3dDegree.d.ts.map +1 -1
  23. package/lib/exercises/math/derivation/variations/signVarTable3dDegree.js +235 -231
  24. package/lib/exercises/math/python/index.d.ts +1 -0
  25. package/lib/exercises/math/python/index.d.ts.map +1 -1
  26. package/lib/exercises/math/python/index.js +1 -0
  27. package/lib/exercises/math/python/list/index.d.ts +11 -0
  28. package/lib/exercises/math/python/list/index.d.ts.map +1 -0
  29. package/lib/exercises/math/python/list/index.js +10 -0
  30. package/lib/exercises/math/python/list/pyListAppend.d.ts +29 -0
  31. package/lib/exercises/math/python/list/pyListAppend.d.ts.map +1 -0
  32. package/lib/exercises/math/python/list/pyListAppend.js +280 -0
  33. package/lib/exercises/math/python/list/pyListCreateListByComprehension.d.ts +11 -0
  34. package/lib/exercises/math/python/list/pyListCreateListByComprehension.d.ts.map +1 -0
  35. package/lib/exercises/math/python/list/pyListCreateListByComprehension.js +231 -0
  36. package/lib/exercises/math/python/list/pyListCreateListInstructionCompletion.d.ts +9 -0
  37. package/lib/exercises/math/python/list/pyListCreateListInstructionCompletion.d.ts.map +1 -0
  38. package/lib/exercises/math/python/list/pyListCreateListInstructionCompletion.js +232 -0
  39. package/lib/exercises/math/python/list/pyListElemAtIndex.d.ts +9 -0
  40. package/lib/exercises/math/python/list/pyListElemAtIndex.d.ts.map +1 -0
  41. package/lib/exercises/math/python/list/pyListElemAtIndex.js +292 -0
  42. package/lib/exercises/math/python/list/pyListMutationMix.d.ts +29 -0
  43. package/lib/exercises/math/python/list/pyListMutationMix.d.ts.map +1 -0
  44. package/lib/exercises/math/python/list/pyListMutationMix.js +455 -0
  45. package/lib/exercises/math/python/list/pyListRemove.d.ts +29 -0
  46. package/lib/exercises/math/python/list/pyListRemove.d.ts.map +1 -0
  47. package/lib/exercises/math/python/list/pyListRemove.js +375 -0
  48. package/lib/exercises/math/python/list/pyListSetElemAtIndex.d.ts +29 -0
  49. package/lib/exercises/math/python/list/pyListSetElemAtIndex.d.ts.map +1 -0
  50. package/lib/exercises/math/python/list/pyListSetElemAtIndex.js +331 -0
  51. package/lib/exercises/math/python/list/pyListSetElemAtIndexInstructionCompletion.d.ts +9 -0
  52. package/lib/exercises/math/python/list/pyListSetElemAtIndexInstructionCompletion.d.ts.map +1 -0
  53. package/lib/exercises/math/python/list/pyListSetElemAtIndexInstructionCompletion.js +346 -0
  54. package/lib/exercises/math/python/list/pyListSetElemAtIndexWaterfall.d.ts +29 -0
  55. package/lib/exercises/math/python/list/pyListSetElemAtIndexWaterfall.d.ts.map +1 -0
  56. package/lib/exercises/math/python/list/pyListSetElemAtIndexWaterfall.js +394 -0
  57. package/lib/geogebra/geogebraConstructor.d.ts +1 -0
  58. package/lib/geogebra/geogebraConstructor.d.ts.map +1 -1
  59. package/lib/geogebra/geogebraConstructor.js +3 -0
  60. package/lib/index.d.ts +280 -0
  61. package/lib/index.d.ts.map +1 -1
  62. package/lib/math/geometry/line.js +1 -1
  63. package/lib/tree/nodes/functions/sqrtNode.d.ts +1 -1
  64. package/lib/tree/nodes/functions/sqrtNode.d.ts.map +1 -1
  65. package/lib/tree/nodes/functions/sqrtNode.js +5 -3
  66. package/package.json +1 -1
@@ -0,0 +1,375 @@
1
+ import { addValidProp, propWhile, shuffleProps, tryToAddWrongProp, } from "../../../../exercises/exercise.js";
2
+ import { getDistinctQuestions } from "../../../../exercises/utils/getDistinctQuestions.js";
3
+ import { randint } from "../../../../math/utils/random/randint.js";
4
+ import { coinFlip } from "../../../../utils/alea/coinFlip.js";
5
+ import { probaFlip } from "../../../../utils/alea/probaFlip.js";
6
+ import { random, randomMany } from "../../../../utils/alea/random.js";
7
+ import { shuffle } from "../../../../utils/alea/shuffle.js";
8
+ import { zip } from "../../../../utils/arrays/arrayZip.js";
9
+ import { mdTable } from "../../../../utils/markdown/mdTable.js";
10
+ const getStrPythonInstruction = (instruction) => {
11
+ const { nameList, value } = instruction;
12
+ switch (instruction.type) {
13
+ case "append":
14
+ {
15
+ return `${nameList}.append(${strPythonForListElem(value)})`;
16
+ }
17
+ break;
18
+ case "remove":
19
+ {
20
+ return `${nameList}.remove(${strPythonForListElem(value)})`;
21
+ }
22
+ break;
23
+ case "injection":
24
+ {
25
+ const { index } = instruction;
26
+ return `${nameList}[${index}] = ${strPythonForListElem(value)}`;
27
+ }
28
+ break;
29
+ }
30
+ };
31
+ const codify = (strPython) => {
32
+ return `\`\`\`python
33
+ ${strPython}
34
+ \`\`\``;
35
+ };
36
+ const codifyChunk = (strPython) => {
37
+ return `\`${strPython}\``;
38
+ };
39
+ const strPythonForList = (list) => {
40
+ return `[${list.map((elem) => strPythonForListElem(elem)).join(", ")}]`;
41
+ };
42
+ const strPythonForListElem = (elem) => {
43
+ if (typeof elem === "string") {
44
+ if (elem === "None") {
45
+ return `${elem}`;
46
+ }
47
+ else {
48
+ return `'${elem}'`;
49
+ }
50
+ }
51
+ else {
52
+ return `${elem}`;
53
+ }
54
+ };
55
+ const getStrPythonProgram = (identifiers) => {
56
+ const { nameList, listInitial, arrInstruction } = identifiers;
57
+ return `${nameList} = ${strPythonForList(listInitial)}
58
+ ${arrInstruction.map(getStrPythonInstruction).join(`
59
+
60
+ `)}
61
+ print(${nameList})
62
+ `;
63
+ };
64
+ const getFunctionPythonInstruction = (instruction) => {
65
+ return (l) => {
66
+ const { nameList, value } = instruction;
67
+ switch (instruction.type) {
68
+ case "append":
69
+ {
70
+ const lWork = [...l];
71
+ lWork.push(value);
72
+ return lWork;
73
+ }
74
+ break;
75
+ case "remove":
76
+ {
77
+ const lWork = [...l];
78
+ const indexFound = lWork.findIndex((v) => v === value);
79
+ if (indexFound === -1) {
80
+ throw new Error(`ValueError: ${nameList}.remove(x): x not in list`);
81
+ }
82
+ lWork.splice(indexFound, 1);
83
+ return lWork;
84
+ }
85
+ break;
86
+ case "injection":
87
+ {
88
+ const { index } = instruction;
89
+ const lWork = [...l];
90
+ lWork[index] = value;
91
+ return lWork;
92
+ }
93
+ break;
94
+ }
95
+ };
96
+ };
97
+ const getFunctionForPythonProgram = (identifiers) => {
98
+ const { nameList, listInitial, arrInstruction } = identifiers;
99
+ return (..._otherArgs) => {
100
+ const outDict = {};
101
+ //init
102
+ let list = listInitial;
103
+ outDict[0] = {
104
+ [nameList]: list,
105
+ };
106
+ //main
107
+ {
108
+ arrInstruction.forEach((instruction, i) => {
109
+ let err;
110
+ try {
111
+ list = getFunctionPythonInstruction(instruction)(list);
112
+ }
113
+ catch (e) {
114
+ err = e;
115
+ }
116
+ outDict[i + 1] = {
117
+ [nameList]: list,
118
+ err,
119
+ };
120
+ });
121
+ }
122
+ //convenience: store last step in -1
123
+ outDict[-1] = outDict[Math.max(...Object.keys(outDict).map((k) => +k))];
124
+ return outDict;
125
+ };
126
+ };
127
+ const getInstruction = (identifiers) => {
128
+ return `Qu'affichera le script en Python suivant ?
129
+
130
+ ${codify(getStrPythonProgram(identifiers))}
131
+
132
+ `;
133
+ };
134
+ const getAnswer = (identifiers) => {
135
+ const { nameList } = identifiers;
136
+ const stepDictEnd = getFunctionForPythonProgram(identifiers)()[-1];
137
+ if (stepDictEnd.err) {
138
+ return `${stepDictEnd.err.message}`;
139
+ }
140
+ else {
141
+ return strPythonForList(stepDictEnd[nameList]);
142
+ }
143
+ };
144
+ const getHint = () => {
145
+ return `En anglais, remove signifie retirer.
146
+
147
+ L'instruction retire le premier élément de la liste qui a la valeur donnée en argument.
148
+ Si aucun élément dans la liste n'a la valeur donnée, un message d'erreur s'affiche.`;
149
+ };
150
+ const getCorrection = (identifiers) => {
151
+ const { nameList, arrInstruction } = identifiers;
152
+ const dictSteps = getFunctionForPythonProgram(identifiers)();
153
+ const maxLength = Math.max(...Object.entries(dictSteps).map(([_, { [nameList]: l }]) => l.length));
154
+ const err = dictSteps[-1].err;
155
+ if (err === undefined) {
156
+ return `Voici l'évolution de la liste $${nameList}$ au fil des instructions.
157
+
158
+ ${mdTable([
159
+ (() => {
160
+ const l = dictSteps[0][nameList];
161
+ return [
162
+ "\\text{Initialement}",
163
+ ...[...Array(maxLength).keys()].map((i) => l.length > i ? `\\text{${l[i]}}` : "\\text{}"),
164
+ ];
165
+ })(),
166
+ ...arrInstruction.map((instruction, i) => {
167
+ const l = dictSteps[i + 1][nameList];
168
+ return [
169
+ `\\text{Après ${getStrPythonInstruction(instruction)}}`,
170
+ ...[...Array(maxLength).keys()].map((i) => l.length > i ? `\\text{${l[i]}}` : "\\text{}"),
171
+ ];
172
+ }),
173
+ ], true)}
174
+
175
+ Le programme affichera donc :
176
+
177
+ ${codify(getAnswer(identifiers))}
178
+
179
+ `;
180
+ }
181
+ else {
182
+ const instructionRemove = arrInstruction[0];
183
+ const valueRemoved = instructionRemove.value;
184
+ return `Quand l'instruction ${codifyChunk(getStrPythonInstruction(instructionRemove))} va être exécutée,
185
+
186
+ étant donné qu'il n'y a aucun élément de $${nameList}$ qui a la valeur ${codifyChunk(strPythonForListElem(valueRemoved))}, l'exécution ne va pas pouvoir s'effectuer correctement.
187
+
188
+ Un message d'erreur va donc s'afficher.`;
189
+ }
190
+ };
191
+ const getPropositions = (n, { answer, ...identifiers }) => {
192
+ const propositions = [];
193
+ addValidProp(propositions, codifyChunk(answer), "raw");
194
+ const { nameList, listInitial, arrInstruction } = identifiers;
195
+ const stepDictEnd = getFunctionForPythonProgram(identifiers)()[-1];
196
+ const lFinal = stepDictEnd[nameList];
197
+ const [instructionRemove] = arrInstruction;
198
+ const valueRemoved = instructionRemove.value;
199
+ //student: remove n elements with n=value
200
+ if (typeof valueRemoved === "number") {
201
+ //at end
202
+ {
203
+ const lWrong = lFinal.slice(0, -valueRemoved);
204
+ tryToAddWrongProp(propositions, codifyChunk(strPythonForList(lWrong)), "raw");
205
+ }
206
+ //at start
207
+ {
208
+ const lWrong = lFinal.slice(valueRemoved);
209
+ tryToAddWrongProp(propositions, codifyChunk(strPythonForList(lWrong)), "raw");
210
+ }
211
+ }
212
+ //student: remove ALL elements that equal value
213
+ {
214
+ const lWrong = lFinal.filter((v) => v !== valueRemoved);
215
+ tryToAddWrongProp(propositions, codifyChunk(strPythonForList(lWrong)), "raw");
216
+ }
217
+ //student: replace value with null
218
+ {
219
+ //replace
220
+ {
221
+ const indexFound = listInitial.findIndex((v) => v === valueRemoved);
222
+ const lWrong = [...listInitial];
223
+ lWrong[indexFound] = "None";
224
+ tryToAddWrongProp(propositions, codifyChunk(strPythonForList(lWrong)), "raw");
225
+ }
226
+ //replaceAll
227
+ {
228
+ const lWrong = listInitial.map((v) => (v === valueRemoved ? "None" : v));
229
+ tryToAddWrongProp(propositions, codifyChunk(strPythonForList(lWrong)), "raw");
230
+ }
231
+ }
232
+ //student: remove, but from right to left
233
+ {
234
+ const identifiersWrong = Object.assign({}, identifiers, {
235
+ listInitial: listInitial.toReversed(),
236
+ });
237
+ const stepDictEnd = getFunctionForPythonProgram(identifiersWrong)()[-1];
238
+ const lWrong = stepDictEnd[nameList].toReversed();
239
+ tryToAddWrongProp(propositions, codifyChunk(strPythonForList(lWrong)), "raw");
240
+ }
241
+ //error message
242
+ {
243
+ const valueAlien = "---";
244
+ const identifiersWrong = {
245
+ ...identifiers,
246
+ arrInstruction: arrInstruction.map((instruction) => {
247
+ return { ...instruction, value: valueAlien };
248
+ }),
249
+ };
250
+ tryToAddWrongProp(propositions, codifyChunk(getAnswer(identifiersWrong)), "raw");
251
+ }
252
+ //student: remove other value
253
+ {
254
+ const valueOther = random(listInitial.filter((v) => v !== valueRemoved));
255
+ const identifiersWrong = {
256
+ ...identifiers,
257
+ arrInstruction: arrInstruction.map((instruction) => {
258
+ return { ...instruction, value: valueOther };
259
+ }),
260
+ };
261
+ const stepDictEnd = getFunctionForPythonProgram(identifiersWrong)()[-1];
262
+ const lWrong = stepDictEnd[nameList];
263
+ tryToAddWrongProp(propositions, codifyChunk(strPythonForList(lWrong)), "raw");
264
+ }
265
+ //student: append value
266
+ {
267
+ const identifiersWrong = {
268
+ ...identifiers,
269
+ arrInstruction: arrInstruction.map((instruction) => {
270
+ console.log("instruction", instruction);
271
+ return {
272
+ ...instruction,
273
+ type: "append",
274
+ value: instruction.value,
275
+ };
276
+ }),
277
+ };
278
+ const stepDictEnd = getFunctionForPythonProgram(identifiersWrong)()[-1];
279
+ const lWrong = stepDictEnd[nameList];
280
+ tryToAddWrongProp(propositions, codifyChunk(strPythonForList(lWrong)), "raw");
281
+ }
282
+ //terror: display tweaked good answer: remove first value
283
+ if (coinFlip()) {
284
+ const lWrong = lFinal.slice(1);
285
+ tryToAddWrongProp(propositions, codifyChunk(strPythonForList(lWrong)), "raw");
286
+ }
287
+ //filler
288
+ propWhile(propositions, n, () => {
289
+ {
290
+ const lWrong = shuffle(lFinal);
291
+ tryToAddWrongProp(propositions, codifyChunk(strPythonForList(lWrong)), "raw");
292
+ }
293
+ {
294
+ const lWrong = shuffle(listInitial);
295
+ tryToAddWrongProp(propositions, codifyChunk(strPythonForList(lWrong)), "raw");
296
+ }
297
+ });
298
+ return shuffleProps(propositions, n);
299
+ };
300
+ const createRandomIdentifiers = () => {
301
+ const poolNameList = ["l", "lst", "liste"];
302
+ const nameList = random(poolNameList);
303
+ function createRandomListInitial(minLength, maxLength) {
304
+ const length = randint(minLength, maxLength + 1);
305
+ const poolNumber = [...Array(61).keys()].map((i) => i - 30);
306
+ const subPoolNumber = randomMany(poolNumber, Math.max(Math.floor(length * 1.5), length + 2));
307
+ const listNumber = [...Array(length).keys()].map(() => random(subPoolNumber));
308
+ const poolLetter = "abcdefghijklmnopqrstuvwxyz".split("");
309
+ const subPoolLetters = randomMany(poolLetter, Math.max(Math.floor(length * 1.5), length + 2));
310
+ const listLetters = [...Array(length).keys()].map(() => random(subPoolLetters));
311
+ const rand = randint(0, 4);
312
+ switch (rand) {
313
+ case 0:
314
+ return listNumber;
315
+ case 1:
316
+ return listLetters;
317
+ case 2: {
318
+ return [...Array(length).keys()].map(() => {
319
+ const word = [...Array(randint(1, 4)).keys()]
320
+ .map(() => random(poolLetter))
321
+ .join("");
322
+ return word;
323
+ });
324
+ }
325
+ case 3:
326
+ return zip(listNumber, listLetters).map(([n, letter]) => random([n, letter]));
327
+ default:
328
+ throw new Error("Unsupported rand: " + rand);
329
+ }
330
+ }
331
+ const [valueEx, ...listInitial] = createRandomListInitial(3, 7);
332
+ const arrInstruction = [
333
+ (() => {
334
+ const value = probaFlip(0.8) ? random(listInitial) : valueEx;
335
+ const instruction = {
336
+ type: "remove",
337
+ nameList,
338
+ value,
339
+ };
340
+ return instruction;
341
+ })(),
342
+ ];
343
+ const identifiers = { nameList, listInitial, arrInstruction };
344
+ return identifiers;
345
+ };
346
+ const getPyListRemoveQuestion = () => {
347
+ const identifiers = createRandomIdentifiers();
348
+ return getQuestionFromIdentifiers(identifiers);
349
+ };
350
+ const getQuestionFromIdentifiers = (identifiers, opts) => {
351
+ const question = {
352
+ answer: getAnswer(identifiers, opts),
353
+ instruction: getInstruction(identifiers, opts),
354
+ keys: [],
355
+ answerFormat: "tex",
356
+ identifiers,
357
+ hint: getHint(identifiers, opts),
358
+ correction: getCorrection(identifiers, opts),
359
+ options: opts,
360
+ };
361
+ return question;
362
+ };
363
+ export const pyListRemove = {
364
+ id: "pyListRemove",
365
+ label: "Retirer un élément dans une liste en Python",
366
+ isSingleStep: true,
367
+ generator: (nb, opts) => getDistinctQuestions(() => getPyListRemoveQuestion(opts), nb),
368
+ qcmTimer: 60,
369
+ freeTimer: 60,
370
+ getPropositions,
371
+ subject: "Mathématiques",
372
+ getQuestionFromIdentifiers,
373
+ hasHintAndCorrection: true,
374
+ answerType: "QCU",
375
+ };
@@ -0,0 +1,29 @@
1
+ import { Exercise } from "../../../../exercises/exercise.js";
2
+ type Append<T> = {
3
+ nameList: string;
4
+ value: T;
5
+ };
6
+ type Remove<T> = {
7
+ nameList: string;
8
+ value: T;
9
+ };
10
+ type Inject<T> = {
11
+ nameList: string;
12
+ index: number;
13
+ value: T;
14
+ };
15
+ type Instruction<T> = ({
16
+ type: "append";
17
+ } & Append<T>) | ({
18
+ type: "remove";
19
+ } & Remove<T>) | ({
20
+ type: "inject";
21
+ } & Inject<T>);
22
+ type Identifiers = {
23
+ nameList: string;
24
+ listInitial: unknown[];
25
+ arrInstruction: Instruction<unknown>[];
26
+ };
27
+ export declare const pyListSetElemAtIndex: Exercise<Identifiers>;
28
+ export {};
29
+ //# sourceMappingURL=pyListSetElemAtIndex.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pyListSetElemAtIndex.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/python/list/pyListSetElemAtIndex.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAcT,MAAM,6BAA6B,CAAC;AA0IrC,KAAK,MAAM,CAAC,CAAC,IAAI;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,CAAC,CAAC;CACV,CAAC;AAEF,KAAK,MAAM,CAAC,CAAC,IAAI;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,CAAC,CAAC;CACV,CAAC;AAEF,KAAK,MAAM,CAAC,CAAC,IAAI;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,CAAC,CAAC;CACV,CAAC;AAEF,KAAK,WAAW,CAAC,CAAC,IACd,CAAC;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,GAChC,CAAC;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,GAChC,CAAC;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAErC,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,OAAO,EAAE,CAAC;IACvB,cAAc,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;CACxC,CAAC;AAqSF,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,WAAW,CAatD,CAAC"}