math-exercises 3.0.185 → 3.0.187

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 (73) 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/derivativeReadingByManipulatingSecant.d.ts.map +1 -1
  16. package/lib/exercises/math/derivation/tangent/derivativeReadingByManipulatingSecant.js +0 -4
  17. package/lib/exercises/math/derivation/tangent/index.d.ts +9 -0
  18. package/lib/exercises/math/derivation/tangent/index.d.ts.map +1 -1
  19. package/lib/exercises/math/derivation/tangent/index.js +9 -0
  20. package/lib/exercises/math/derivation/variations/findAbscissaOfExtremaFromFunctionExpression.d.ts.map +1 -1
  21. package/lib/exercises/math/derivation/variations/findAbscissaOfExtremaFromFunctionExpression.js +3 -22
  22. package/lib/exercises/math/derivation/variations/index.d.ts +8 -0
  23. package/lib/exercises/math/derivation/variations/index.d.ts.map +1 -1
  24. package/lib/exercises/math/derivation/variations/index.js +8 -0
  25. package/lib/exercises/math/derivation/variations/signVarTable3dDegree.d.ts +10 -0
  26. package/lib/exercises/math/derivation/variations/signVarTable3dDegree.d.ts.map +1 -1
  27. package/lib/exercises/math/derivation/variations/signVarTable3dDegree.js +235 -231
  28. package/lib/exercises/math/functions/basics/inverseImageFunction.js +1 -1
  29. package/lib/exercises/math/functions/sign/affineSignTable.d.ts.map +1 -1
  30. package/lib/exercises/math/functions/sign/affineSignTable.js +1 -1
  31. package/lib/exercises/math/python/index.d.ts +1 -0
  32. package/lib/exercises/math/python/index.d.ts.map +1 -1
  33. package/lib/exercises/math/python/index.js +1 -0
  34. package/lib/exercises/math/python/list/index.d.ts +11 -0
  35. package/lib/exercises/math/python/list/index.d.ts.map +1 -0
  36. package/lib/exercises/math/python/list/index.js +10 -0
  37. package/lib/exercises/math/python/list/pyListAppend.d.ts +29 -0
  38. package/lib/exercises/math/python/list/pyListAppend.d.ts.map +1 -0
  39. package/lib/exercises/math/python/list/pyListAppend.js +280 -0
  40. package/lib/exercises/math/python/list/pyListCreateListByComprehension.d.ts +11 -0
  41. package/lib/exercises/math/python/list/pyListCreateListByComprehension.d.ts.map +1 -0
  42. package/lib/exercises/math/python/list/pyListCreateListByComprehension.js +231 -0
  43. package/lib/exercises/math/python/list/pyListCreateListInstructionCompletion.d.ts +9 -0
  44. package/lib/exercises/math/python/list/pyListCreateListInstructionCompletion.d.ts.map +1 -0
  45. package/lib/exercises/math/python/list/pyListCreateListInstructionCompletion.js +232 -0
  46. package/lib/exercises/math/python/list/pyListElemAtIndex.d.ts +9 -0
  47. package/lib/exercises/math/python/list/pyListElemAtIndex.d.ts.map +1 -0
  48. package/lib/exercises/math/python/list/pyListElemAtIndex.js +292 -0
  49. package/lib/exercises/math/python/list/pyListMutationMix.d.ts +29 -0
  50. package/lib/exercises/math/python/list/pyListMutationMix.d.ts.map +1 -0
  51. package/lib/exercises/math/python/list/pyListMutationMix.js +455 -0
  52. package/lib/exercises/math/python/list/pyListRemove.d.ts +29 -0
  53. package/lib/exercises/math/python/list/pyListRemove.d.ts.map +1 -0
  54. package/lib/exercises/math/python/list/pyListRemove.js +375 -0
  55. package/lib/exercises/math/python/list/pyListSetElemAtIndex.d.ts +29 -0
  56. package/lib/exercises/math/python/list/pyListSetElemAtIndex.d.ts.map +1 -0
  57. package/lib/exercises/math/python/list/pyListSetElemAtIndex.js +331 -0
  58. package/lib/exercises/math/python/list/pyListSetElemAtIndexInstructionCompletion.d.ts +9 -0
  59. package/lib/exercises/math/python/list/pyListSetElemAtIndexInstructionCompletion.d.ts.map +1 -0
  60. package/lib/exercises/math/python/list/pyListSetElemAtIndexInstructionCompletion.js +346 -0
  61. package/lib/exercises/math/python/list/pyListSetElemAtIndexWaterfall.d.ts +29 -0
  62. package/lib/exercises/math/python/list/pyListSetElemAtIndexWaterfall.d.ts.map +1 -0
  63. package/lib/exercises/math/python/list/pyListSetElemAtIndexWaterfall.js +394 -0
  64. package/lib/geogebra/geogebraConstructor.d.ts +1 -0
  65. package/lib/geogebra/geogebraConstructor.d.ts.map +1 -1
  66. package/lib/geogebra/geogebraConstructor.js +3 -0
  67. package/lib/index.d.ts +280 -0
  68. package/lib/index.d.ts.map +1 -1
  69. package/lib/math/geometry/line.js +1 -1
  70. package/lib/tree/nodes/functions/sqrtNode.d.ts +1 -1
  71. package/lib/tree/nodes/functions/sqrtNode.d.ts.map +1 -1
  72. package/lib/tree/nodes/functions/sqrtNode.js +5 -3
  73. package/package.json +1 -1
@@ -0,0 +1,280 @@
1
+ import { addValidProp, 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 { random, randomMany } from "../../../../utils/alea/random.js";
5
+ import { zip } from "../../../../utils/arrays/arrayZip.js";
6
+ import { mdTable } from "../../../../utils/markdown/mdTable.js";
7
+ const getStrPythonInstruction = (instruction) => {
8
+ const { nameList, value } = instruction;
9
+ switch (instruction.type) {
10
+ case "append":
11
+ {
12
+ return `${nameList}.append(${strPythonForListElem(value)})`;
13
+ }
14
+ break;
15
+ case "remove":
16
+ {
17
+ return `${nameList}.remove(${strPythonForListElem(value)})`;
18
+ }
19
+ break;
20
+ case "injection":
21
+ {
22
+ const { index } = instruction;
23
+ return `${nameList}[${index}] = ${strPythonForListElem(value)}`;
24
+ }
25
+ break;
26
+ }
27
+ };
28
+ const codify = (strPython) => {
29
+ return `\`\`\`python
30
+ ${strPython}
31
+ \`\`\``;
32
+ };
33
+ const codifyChunk = (strPython) => {
34
+ return `\`${strPython}\``;
35
+ };
36
+ const strPythonForList = (list) => {
37
+ return `[${list.map((elem) => strPythonForListElem(elem)).join(", ")}]`;
38
+ };
39
+ const strPythonForListElem = (elem) => {
40
+ if (typeof elem === "string") {
41
+ return `'${elem}'`;
42
+ }
43
+ else {
44
+ return `${elem}`;
45
+ }
46
+ };
47
+ const getStrPythonProgram = (identifiers) => {
48
+ const { nameList, listInitial, arrInstruction } = identifiers;
49
+ return `${nameList} = ${strPythonForList(listInitial)}
50
+ ${arrInstruction.map(getStrPythonInstruction).join(`
51
+
52
+ `)}
53
+ print(${nameList})
54
+ `;
55
+ };
56
+ const getFunctionPythonInstruction = (instruction) => {
57
+ return (l) => {
58
+ const { nameList, value } = instruction;
59
+ switch (instruction.type) {
60
+ case "append":
61
+ {
62
+ const lWork = [...l];
63
+ lWork.push(value);
64
+ return lWork;
65
+ }
66
+ break;
67
+ case "remove":
68
+ {
69
+ const lWork = [...l];
70
+ const indexFound = lWork.indexOf(value);
71
+ if (indexFound === -1) {
72
+ throw new Error(`ValueError: ${nameList}.remove(x): x not in list`);
73
+ }
74
+ lWork.splice(indexFound, 1);
75
+ return lWork;
76
+ }
77
+ break;
78
+ case "injection":
79
+ {
80
+ const { index } = instruction;
81
+ const lWork = [...l];
82
+ lWork[index] = value;
83
+ return lWork;
84
+ }
85
+ break;
86
+ }
87
+ };
88
+ };
89
+ const getFunctionForPythonProgram = (identifiers) => {
90
+ const { nameList, listInitial, arrInstruction } = identifiers;
91
+ return (..._otherArgs) => {
92
+ const outDict = {};
93
+ //init
94
+ let list = listInitial;
95
+ outDict[0] = {
96
+ [nameList]: list,
97
+ };
98
+ //main
99
+ {
100
+ arrInstruction.forEach((instruction, i) => {
101
+ list = getFunctionPythonInstruction(instruction)(list);
102
+ outDict[i + 1] = {
103
+ [nameList]: list,
104
+ };
105
+ });
106
+ }
107
+ //convenience: store last step in -1
108
+ outDict[-1] = outDict[Math.max(...Object.keys(outDict).map((k) => +k))];
109
+ return outDict;
110
+ };
111
+ };
112
+ const getInstruction = (identifiers) => {
113
+ return `Qu'affichera le script en Python suivant ?
114
+
115
+ ${codify(getStrPythonProgram(identifiers))}
116
+
117
+ `;
118
+ };
119
+ const getAnswer = (identifiers) => {
120
+ const { nameList } = identifiers;
121
+ const stepDictEnd = getFunctionForPythonProgram(identifiers)()[-1];
122
+ return strPythonForList(stepDictEnd[nameList]);
123
+ };
124
+ const getHint = () => {
125
+ return `En anglais, append signifie ajouter à la fin.`;
126
+ };
127
+ const getCorrection = (identifiers) => {
128
+ const { nameList, arrInstruction } = identifiers;
129
+ const dictSteps = getFunctionForPythonProgram(identifiers)();
130
+ const maxLength = Math.max(...Object.entries(dictSteps).map(([_, { [nameList]: l }]) => l.length));
131
+ return `Voici l'évolution de la liste $${nameList}$ au fil des instructions.
132
+
133
+ ${mdTable([
134
+ (() => {
135
+ const l = dictSteps[0][nameList];
136
+ return [
137
+ "\\text{Initialement}",
138
+ ...[...Array(maxLength).keys()].map((i) => l.length > i ? `\\text{${l[i]}}` : "\\text{}"),
139
+ ];
140
+ })(),
141
+ ...arrInstruction.map((instruction, i) => {
142
+ const l = dictSteps[i + 1][nameList];
143
+ return [
144
+ `\\text{Après ${getStrPythonInstruction(instruction)}}`,
145
+ ...[...Array(maxLength).keys()].map((i) => l.length > i ? `\\text{${l[i]}}` : "\\text{}"),
146
+ ];
147
+ }),
148
+ ], true)}
149
+
150
+ Le programme affichera donc :
151
+
152
+ ${codify(getAnswer(identifiers))}
153
+
154
+ `;
155
+ };
156
+ const getPropositions = (n, { answer, ...identifiers }) => {
157
+ const propositions = [];
158
+ addValidProp(propositions, codifyChunk(answer), "raw");
159
+ const { nameList } = identifiers;
160
+ const stepDictEnd = getFunctionForPythonProgram(identifiers)()[-1];
161
+ const lFinal = stepDictEnd[nameList];
162
+ //student: add at start instead of append
163
+ {
164
+ const lWrong = [lFinal[lFinal.length - 1], ...lFinal.slice(0, -1)];
165
+ tryToAddWrongProp(propositions, codifyChunk(strPythonForList(lWrong)), "raw");
166
+ }
167
+ //student: add at start + append
168
+ {
169
+ const lWrong = [lFinal[lFinal.length - 1], ...lFinal];
170
+ tryToAddWrongProp(propositions, codifyChunk(strPythonForList(lWrong)), "raw");
171
+ }
172
+ //student: l.append(v) -> l = [v]
173
+ {
174
+ const value = lFinal[lFinal.length - 1];
175
+ const lWrong = [value];
176
+ tryToAddWrongProp(propositions, codifyChunk(strPythonForList(lWrong)), "raw");
177
+ }
178
+ //student: concat to last value instead of append to list
179
+ {
180
+ const lWrong = [
181
+ ...lFinal.slice(0, -2),
182
+ `${lFinal[lFinal.length - 2]}${lFinal[lFinal.length - 1]}`,
183
+ ];
184
+ tryToAddWrongProp(propositions, codifyChunk(strPythonForList(lWrong)), "raw");
185
+ }
186
+ //student: splits value and appends each char
187
+ {
188
+ const value = lFinal[lFinal.length - 1];
189
+ const lWrong = [
190
+ ...lFinal.slice(0, -1),
191
+ ...`${value}`.split("").map((c) => {
192
+ const n = Number(c);
193
+ if (n) {
194
+ return n;
195
+ }
196
+ else {
197
+ return c;
198
+ }
199
+ }),
200
+ ];
201
+ tryToAddWrongProp(propositions, codifyChunk(strPythonForList(lWrong)), "raw");
202
+ }
203
+ //terror: display tweaked good answer: remove first value
204
+ {
205
+ const lWrong = lFinal.slice(1);
206
+ tryToAddWrongProp(propositions, codifyChunk(strPythonForList(lWrong)), "raw");
207
+ }
208
+ return shuffleProps(propositions, n);
209
+ };
210
+ const createRandomIdentifiers = () => {
211
+ const poolNameList = ["l", "lst", "liste"];
212
+ const nameList = random(poolNameList);
213
+ function createRandomListInitial(minLength, maxLength) {
214
+ const length = randint(minLength, maxLength + 1);
215
+ const poolNumber = [...Array(61).keys()].map((i) => i - 30);
216
+ const listNumber = randomMany(poolNumber, length);
217
+ const poolLetter = "abcdefghijklmnopqrstuvwxyz".split("");
218
+ const listLetters = randomMany(poolLetter, length);
219
+ const rand = randint(0, 4);
220
+ switch (rand) {
221
+ case 0:
222
+ return listNumber;
223
+ case 1:
224
+ return listLetters;
225
+ case 2: {
226
+ return [...Array(length).keys()].map(() => {
227
+ const word = [...Array(randint(2, 5)).keys()]
228
+ .map(() => random(poolLetter))
229
+ .join("");
230
+ return word;
231
+ });
232
+ }
233
+ case 3:
234
+ return zip(listNumber, listLetters).map(([n, letter]) => random([n, letter]));
235
+ default:
236
+ throw new Error("Unsupported rand: " + rand);
237
+ }
238
+ }
239
+ const listInitial = createRandomListInitial(2, 5);
240
+ const arrInstruction = createRandomListInitial(1, 1).map((v) => {
241
+ const instruction = {
242
+ type: "append",
243
+ nameList,
244
+ value: v,
245
+ };
246
+ return instruction;
247
+ });
248
+ const identifiers = { nameList, listInitial, arrInstruction };
249
+ return identifiers;
250
+ };
251
+ const getPyListAppendQuestion = () => {
252
+ const identifiers = createRandomIdentifiers();
253
+ return getQuestionFromIdentifiers(identifiers);
254
+ };
255
+ const getQuestionFromIdentifiers = (identifiers, opts) => {
256
+ const question = {
257
+ answer: getAnswer(identifiers, opts),
258
+ instruction: getInstruction(identifiers, opts),
259
+ keys: [],
260
+ answerFormat: "tex",
261
+ identifiers,
262
+ hint: getHint(identifiers, opts),
263
+ correction: getCorrection(identifiers, opts),
264
+ options: opts,
265
+ };
266
+ return question;
267
+ };
268
+ export const pyListAppend = {
269
+ id: "pyListAppend",
270
+ label: "Ajouter un élément dans une liste en Python",
271
+ isSingleStep: true,
272
+ generator: (nb, opts) => getDistinctQuestions(() => getPyListAppendQuestion(opts), nb),
273
+ qcmTimer: 60,
274
+ freeTimer: 60,
275
+ getPropositions,
276
+ subject: "Mathématiques",
277
+ getQuestionFromIdentifiers,
278
+ hasHintAndCorrection: true,
279
+ answerType: "QCU",
280
+ };
@@ -0,0 +1,11 @@
1
+ import { Exercise } from "../../../../exercises/exercise.js";
2
+ import { NodeIdentifiers } from "../../../../tree/nodes/nodeConstructor.js";
3
+ type Identifiers = {
4
+ length: number;
5
+ nodeIdsElemAtIndexI: NodeIdentifiers;
6
+ rand: number;
7
+ randFOfI: number;
8
+ };
9
+ export declare const pyListCreateListByComprehension: Exercise<Identifiers>;
10
+ export {};
11
+ //# sourceMappingURL=pyListCreateListByComprehension.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pyListCreateListByComprehension.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/python/list/pyListCreateListByComprehension.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,6BAA6B,CAAC;AAKrC,OAAO,EAEL,eAAe,EAChB,MAAM,qCAAqC,CAAC;AAwD7C,KAAK,WAAW,GAAG;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,mBAAmB,EAAE,eAAe,CAAC;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAiPF,eAAO,MAAM,+BAA+B,EAAE,QAAQ,CAAC,WAAW,CAgBjE,CAAC"}
@@ -0,0 +1,231 @@
1
+ import { addValidProp, shuffleProps, tryToAddWrongProp, } from "../../../../exercises/exercise.js";
2
+ import { getDistinctQuestions } from "../../../../exercises/utils/getDistinctQuestions.js";
3
+ import { nodeBySubstitutingVar } from "../../../../math/utils/functions/functionComposition.js";
4
+ import { randint } from "../../../../math/utils/random/randint.js";
5
+ import { NodeConstructor, } from "../../../../tree/nodes/nodeConstructor.js";
6
+ import { add } from "../../../../tree/nodes/operators/addNode.js";
7
+ import { multiply } from "../../../../tree/nodes/operators/multiplyNode.js";
8
+ import { power } from "../../../../tree/nodes/operators/powerNode.js";
9
+ import { coinFlip } from "../../../../utils/alea/coinFlip.js";
10
+ import { probaFlip } from "../../../../utils/alea/probaFlip.js";
11
+ import { random } from "../../../../utils/alea/random.js";
12
+ import { zip } from "../../../../utils/arrays/arrayZip.js";
13
+ import { mdTable } from "../../../../utils/markdown/mdTable.js";
14
+ const strPythonFromMathString = (strMathString) => {
15
+ return strMathString;
16
+ };
17
+ const createListByComprehension = (nodeElemAtIndexI, length) => {
18
+ return [...Array(length).keys()].map((i) => {
19
+ return nodeElemAtIndexI.evaluate({ i });
20
+ });
21
+ };
22
+ const codify = (strPython) => {
23
+ return `\`\`\`python
24
+ ${strPython}
25
+ \`\`\``;
26
+ };
27
+ const codifyChunk = (strPython) => {
28
+ return `\`${strPython}\``;
29
+ };
30
+ const strPythonForList = (list) => {
31
+ return `[${list.map((elem) => strPythonForListElem(elem)).join(", ")}]`;
32
+ };
33
+ const strPythonForListElem = (elem) => {
34
+ if (typeof elem === "string") {
35
+ return `'${elem}'`;
36
+ }
37
+ else {
38
+ return `${elem}`;
39
+ }
40
+ };
41
+ const strPythonForListByComprehension = (nodeElemAtIndexI, length) => {
42
+ const strPythonElemAtIndexI = strPythonFromMathString(nodeElemAtIndexI.toMathString());
43
+ return `[${strPythonElemAtIndexI} for i in range(${length})]`;
44
+ };
45
+ const getStrPythonProgram = (identifiers) => {
46
+ const { length, nodeIdsElemAtIndexI } = identifiers;
47
+ const nodeElemAtIndexI = NodeConstructor.fromIdentifiers(nodeIdsElemAtIndexI);
48
+ return `l = ${strPythonForListByComprehension(nodeElemAtIndexI, length)}
49
+ print(l)
50
+ `;
51
+ };
52
+ const getInstruction = (identifiers) => {
53
+ return `Qu'affichera le script en Python suivant ?
54
+
55
+ ${codify(getStrPythonProgram(identifiers))}
56
+
57
+ `;
58
+ };
59
+ const getAnswer = (identifiers) => {
60
+ const { length, nodeIdsElemAtIndexI } = identifiers;
61
+ const nodeElemAtIndexI = NodeConstructor.fromIdentifiers(nodeIdsElemAtIndexI);
62
+ return strPythonForList(createListByComprehension(nodeElemAtIndexI, length));
63
+ };
64
+ const getHint = (identifiers) => {
65
+ const { length, nodeIdsElemAtIndexI } = identifiers;
66
+ const nodeElemAtIndexI = NodeConstructor.fromIdentifiers(nodeIdsElemAtIndexI);
67
+ return `La ligne de code
68
+
69
+ ${codify(`l = ${strPythonForListByComprehension(nodeElemAtIndexI, length)}`)}
70
+
71
+ peut se traduire mathématiquement par :
72
+
73
+ Pour $i$ entier entre $0$ et $${length - 1}$ exclu :
74
+
75
+ $$
76
+ l_{i} = ${nodeElemAtIndexI.toTex()}
77
+ $$
78
+
79
+ `;
80
+ };
81
+ const getCorrection = (identifiers) => {
82
+ const { length, nodeIdsElemAtIndexI } = identifiers;
83
+ const nodeElemAtIndexI = NodeConstructor.fromIdentifiers(nodeIdsElemAtIndexI);
84
+ const strPythonFormulaElemAtIndexI = nodeElemAtIndexI.toMathString();
85
+ const arrI = [...Array(length).keys()];
86
+ const arrList = createListByComprehension(nodeElemAtIndexI, length);
87
+ return `Dans le programme proposé, la liste $l$ est construite par compréhension.
88
+
89
+ Chaque terme est construit en appliquant la formule ${codifyChunk(strPythonFormulaElemAtIndexI)} pour chaque valeur de $i$.
90
+
91
+ ${mdTable([
92
+ [nodeElemAtIndexI.toTex(), "i"],
93
+ ...zip(arrList, arrI).map(([v, i]) => [`${v}`, `${i}`]),
94
+ ], true)}
95
+
96
+ Le programme va donc afficher :
97
+
98
+ ${codify(strPythonForList(arrList))}
99
+
100
+ `;
101
+ };
102
+ const getPropositions = (n, { answer, ...identifiers }) => {
103
+ const propositions = [];
104
+ addValidProp(propositions, codifyChunk(answer), "raw");
105
+ const { length, nodeIdsElemAtIndexI } = identifiers;
106
+ const nodeElemAtIndexI = NodeConstructor.fromIdentifiers(nodeIdsElemAtIndexI);
107
+ const arrArrList = [];
108
+ const arrListWrong = createListByComprehension(nodeElemAtIndexI, length);
109
+ arrArrList.push(arrListWrong);
110
+ //too few / too many
111
+ {
112
+ const lengthWrong = length + (probaFlip(0.7) ? -1 : +1);
113
+ const arrListWrong = createListByComprehension(nodeElemAtIndexI, lengthWrong);
114
+ const strWrong = strPythonForList(arrListWrong);
115
+ tryToAddWrongProp(propositions, codifyChunk(strWrong), "raw");
116
+ arrArrList.push(arrListWrong);
117
+ }
118
+ //starts at i=1
119
+ {
120
+ const arrListWrong = createListByComprehension(nodeBySubstitutingVar(nodeElemAtIndexI, add("i".toTree(), 1), "i".toTree()), length);
121
+ const strWrong = strPythonForList(arrListWrong);
122
+ tryToAddWrongProp(propositions, codifyChunk(strWrong), "raw");
123
+ arrArrList.push(arrListWrong);
124
+ }
125
+ //filler
126
+ {
127
+ [...Array(2).keys()].forEach(() => {
128
+ const identifiersWrong = createRandomIdentifiers();
129
+ const { nodeIdsElemAtIndexI: nodeIdsElemAtIndexIWrong } = identifiersWrong;
130
+ const nodeElemAtIndexIWrong = NodeConstructor.fromIdentifiers(nodeIdsElemAtIndexIWrong);
131
+ const lengthWrong = length + randint(-1, 2);
132
+ const arrListWrong = createListByComprehension(nodeElemAtIndexIWrong, lengthWrong);
133
+ const strWrong = strPythonForList(arrListWrong);
134
+ tryToAddWrongProp(propositions, codifyChunk(strWrong), "raw");
135
+ arrArrList.push(arrListWrong);
136
+ });
137
+ }
138
+ //terror: reversed
139
+ if (coinFlip() || propositions.length < n) {
140
+ const arrListWrong = random(arrArrList).toReversed();
141
+ const strWrong = strPythonForList(arrListWrong);
142
+ tryToAddWrongProp(propositions, codifyChunk(strWrong), "raw");
143
+ }
144
+ return shuffleProps(propositions, n);
145
+ };
146
+ const createRandomIdentifiers = () => {
147
+ const randFOfI = randint(0, 1);
148
+ const nodeI = "i".toTree();
149
+ const nodeFOfI = randFOfI === 0 ? nodeI : add(nodeI, 1);
150
+ const rand = randint(0, 5);
151
+ const nodeElemAtIndexI = (() => {
152
+ switch (rand) {
153
+ case 0:
154
+ {
155
+ //constant
156
+ const c = randint(2, 10);
157
+ return c.toTree();
158
+ }
159
+ break;
160
+ case 1:
161
+ {
162
+ //b + f(i)
163
+ const b = randint(2, 10);
164
+ return add(b.toTree(), nodeFOfI);
165
+ }
166
+ break;
167
+ case 2:
168
+ {
169
+ //a * f(i)
170
+ const a = randint(2, 10);
171
+ return multiply(a.toTree(), nodeFOfI);
172
+ }
173
+ break;
174
+ case 3:
175
+ {
176
+ //a * f(i) + b
177
+ const a = randint(2, 10);
178
+ const b = randint(2, 10, [a]);
179
+ return add(multiply(a.toTree(), nodeFOfI), b.toTree());
180
+ }
181
+ break;
182
+ case 4:
183
+ {
184
+ //k ** f(i)
185
+ const k = random([-2, -1, 2, 3]);
186
+ return power(k.toTree(), nodeFOfI);
187
+ }
188
+ break;
189
+ default:
190
+ throw new Error("Unsupported rand: " + rand);
191
+ }
192
+ })();
193
+ const length = randint(4, 8);
194
+ const identifiers = {
195
+ length,
196
+ nodeIdsElemAtIndexI: nodeElemAtIndexI.toIdentifiers(),
197
+ rand,
198
+ randFOfI,
199
+ };
200
+ return identifiers;
201
+ };
202
+ const getPyListCreateListByComprehensionQuestion = () => {
203
+ const identifiers = createRandomIdentifiers();
204
+ return getQuestionFromIdentifiers(identifiers);
205
+ };
206
+ const getQuestionFromIdentifiers = (identifiers, opts) => {
207
+ const question = {
208
+ answer: getAnswer(identifiers, opts),
209
+ instruction: getInstruction(identifiers, opts),
210
+ keys: [],
211
+ answerFormat: "tex",
212
+ identifiers,
213
+ hint: getHint(identifiers, opts),
214
+ correction: getCorrection(identifiers, opts),
215
+ options: opts,
216
+ };
217
+ return question;
218
+ };
219
+ export const pyListCreateListByComprehension = {
220
+ id: "pyListCreateListByComprehension",
221
+ label: "Créer une liste par compréhension en Python",
222
+ isSingleStep: true,
223
+ generator: (nb, opts) => getDistinctQuestions(() => getPyListCreateListByComprehensionQuestion(opts), nb),
224
+ qcmTimer: 60,
225
+ freeTimer: 60,
226
+ getPropositions,
227
+ subject: "Mathématiques",
228
+ getQuestionFromIdentifiers,
229
+ hasHintAndCorrection: true,
230
+ answerType: "QCU",
231
+ };
@@ -0,0 +1,9 @@
1
+ import { Exercise } from "../../../../exercises/exercise.js";
2
+ type Identifiers = {
3
+ nameList: string;
4
+ listInitial: unknown[];
5
+ indexAsked: number;
6
+ };
7
+ export declare const pyListCreateListInstructionCompletion: Exercise<Identifiers>;
8
+ export {};
9
+ //# sourceMappingURL=pyListCreateListInstructionCompletion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pyListCreateListInstructionCompletion.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/python/list/pyListCreateListInstructionCompletion.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,6BAA6B,CAAC;AA4BrC,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,OAAO,EAAE,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AA2QF,eAAO,MAAM,qCAAqC,EAAE,QAAQ,CAAC,WAAW,CAiBvE,CAAC"}