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,232 @@
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 { probaLawFlip } from "../../../../utils/alea/probaLawFlip.js";
5
+ import { random, randomMany } from "../../../../utils/alea/random.js";
6
+ const codify = (strPython) => {
7
+ return `\`\`\`python
8
+ ${strPython}
9
+ \`\`\``;
10
+ };
11
+ const codifyChunk = (strPython) => {
12
+ return `\`${strPython}\``;
13
+ };
14
+ const strPythonForList = (list) => {
15
+ return `[${list.map((elem) => strPythonForListElem(elem)).join(", ")}]`;
16
+ };
17
+ const strPythonForListElem = (elem) => {
18
+ if (typeof elem === "string") {
19
+ return `'${elem}'`;
20
+ }
21
+ else {
22
+ return `${elem}`;
23
+ }
24
+ };
25
+ const getStrPythonProgramIncomplete = (identifiers) => {
26
+ const { nameList, indexAsked } = identifiers;
27
+ return `...
28
+ print(${nameList}[${indexAsked}])
29
+ `;
30
+ };
31
+ const getInstruction = (identifiers) => {
32
+ const { listInitial, indexAsked } = identifiers;
33
+ return `Par quelle(s) instruction(s) peut-on remplacer les pointillés pour que le programme Python ci-dessous affiche ${codifyChunk(`${listInitial[indexAsked]}`)} ?
34
+
35
+ ${codify(getStrPythonProgramIncomplete(identifiers))}
36
+
37
+ `;
38
+ };
39
+ // const getAnswer: GetAnswer<Identifiers> = (identifiers) => {
40
+ // const { nameList, listInitial } = identifiers;
41
+ // return `${nameList} = ${strPythonForList(listInitial)}`;
42
+ // };
43
+ const createRandomListValid = (identifiers) => {
44
+ const { listInitial, indexAsked } = identifiers;
45
+ const elem = listInitial[indexAsked];
46
+ function createRandomElem() {
47
+ return randint(-30, 31);
48
+ }
49
+ const listLength = randint(indexAsked + 1, listInitial.length);
50
+ return [...Array(listLength).keys()].map((i) => i === indexAsked ? elem : createRandomElem());
51
+ };
52
+ const createRandomListInvalid = (identifiers) => {
53
+ const { listInitial, indexAsked } = identifiers;
54
+ const elem = listInitial[indexAsked];
55
+ function createRandomElem(excludes) {
56
+ return randint(-30, 31, excludes);
57
+ }
58
+ const indexAskedWrong = random([
59
+ ...(indexAsked - 1 >= 0 ? [indexAsked - 1] : []),
60
+ ...(indexAsked + 1 < listInitial.length ? [indexAsked + 1] : []),
61
+ ]);
62
+ const listLength = randint(indexAsked + 1, listInitial.length);
63
+ return [...Array(listLength).keys()].map((i) => i === indexAskedWrong
64
+ ? elem
65
+ : i === indexAsked
66
+ ? createRandomElem([elem])
67
+ : createRandomElem([]));
68
+ };
69
+ const createRandomValidAnswer = (identifiers) => {
70
+ const { nameList } = identifiers;
71
+ const listValid = createRandomListValid(identifiers);
72
+ return codifyChunk(`${nameList} = ${strPythonForList(listValid)}`);
73
+ };
74
+ const getHint = (identifiers) => {
75
+ const { nameList } = identifiers;
76
+ return `Il faut créer une liste, qui sera assignée à la variable $${nameList}$.
77
+
78
+ Pour créer une liste, il faut mettre entre crochets, les éléments séparés par des virgules.
79
+
80
+ Il faut aussi que l'élément récupéré corresponde bien à l'indice utilisé.`;
81
+ };
82
+ const getCorrection = (identifiers) => {
83
+ const { nameList, listInitial, indexAsked } = identifiers;
84
+ return `Dans le programme proposé, la dernière ligne est
85
+
86
+ ${codify(`print(${nameList}[${indexAsked}])`)}
87
+
88
+ Il est donc nécessaire que l'élément à l'indice $${indexAsked}$ soit ${codifyChunk(strPythonForListElem(listInitial[indexAsked]))}.
89
+
90
+ Il est également nécessaire que le nom de la liste soit $${nameList}$.
91
+
92
+ Pour créer une liste, il faut mettre entre crochets, les éléments séparés par des virgules.
93
+
94
+ Les propositions correctes sont toutes celles qui utilisent le nom correct, des crochets et des virgules, et qui ont ${codifyChunk(strPythonForListElem(listInitial[indexAsked]))} à l'indice $${indexAsked}$ :
95
+
96
+ ${codify(`${nameList} = [${[
97
+ ...listInitial
98
+ .slice(0, indexAsked + 1)
99
+ .map((elem, i) => (i === indexAsked ? strPythonForListElem(elem) : "_")),
100
+ "...",
101
+ ].join(", ")}]`)}
102
+
103
+ `;
104
+ };
105
+ const getPropositions = (n, { answer, ...identifiers }) => {
106
+ const { nameList } = identifiers;
107
+ const arrStrForTerror = [];
108
+ //valid
109
+ const propositionsValid = [];
110
+ const nbValid = probaLawFlip([
111
+ [1, 0.45],
112
+ [2, 0.3],
113
+ [3, 0.2],
114
+ [4, 0.05],
115
+ ]);
116
+ {
117
+ propWhile(propositionsValid, nbValid, () => {
118
+ const strAnswer = createRandomValidAnswer(identifiers);
119
+ const isAlreadyAdded = propositionsValid
120
+ .map((proposition) => proposition.statement)
121
+ .includes(strAnswer);
122
+ if (!isAlreadyAdded) {
123
+ addValidProp(propositionsValid, strAnswer, "raw");
124
+ arrStrForTerror.push(strAnswer);
125
+ }
126
+ });
127
+ }
128
+ const maxNbMandatory = n - nbValid;
129
+ const nbMandatory = randint(Math.min(maxNbMandatory, 1), Math.min(maxNbMandatory, 3));
130
+ //very wrong
131
+ const propositionsMandatory = [];
132
+ {
133
+ //student: no []
134
+ {
135
+ const listValid = createRandomListValid(identifiers);
136
+ const strWrong = codifyChunk(`${nameList} = ${strPythonForList(listValid)
137
+ .replace("[", "")
138
+ .replace("]", "")}`);
139
+ tryToAddWrongProp(propositionsMandatory, strWrong, "raw");
140
+ }
141
+ //student: ; instead of ,
142
+ {
143
+ const listValid = createRandomListValid(identifiers);
144
+ const strWrong = codifyChunk(`${nameList} = ${strPythonForList(listValid).replaceAll(",", ";")}`);
145
+ tryToAddWrongProp(propositionsMandatory, strWrong, "raw");
146
+ arrStrForTerror.push(strWrong);
147
+ }
148
+ //student: no [] + ; instead of ,
149
+ {
150
+ const listValid = createRandomListValid(identifiers);
151
+ const strWrong = codifyChunk(`${nameList} = ${strPythonForList(listValid)
152
+ .replace("[", "")
153
+ .replace("]", "")
154
+ .replaceAll(",", ";")}`);
155
+ tryToAddWrongProp(propositionsMandatory, strWrong, "raw");
156
+ }
157
+ }
158
+ //filler/terror
159
+ const propositionsFiller = [];
160
+ {
161
+ //student: elem is not at indexAsked
162
+ {
163
+ [...Array(3).keys()].forEach(() => {
164
+ const listInvalid = createRandomListInvalid(identifiers);
165
+ const strWrong = codifyChunk(`${nameList} = ${strPythonForList(listInvalid)}`);
166
+ tryToAddWrongProp(propositionsFiller, strWrong, "raw");
167
+ arrStrForTerror.push(strWrong);
168
+ });
169
+ }
170
+ //terror: wrong list name
171
+ {
172
+ const poolNameListWrong = [
173
+ ...["l", "lst", "liste"].filter((name) => name !== nameList),
174
+ "list",
175
+ ];
176
+ const nameListWrong = random(poolNameListWrong);
177
+ const arrStrPicked = randomMany(arrStrForTerror, 2);
178
+ arrStrPicked.forEach((strPicked) => {
179
+ const strWrong = strPicked.replace(nameList, nameListWrong);
180
+ tryToAddWrongProp(propositionsFiller, strWrong, "raw");
181
+ });
182
+ }
183
+ }
184
+ return shuffleProps([
185
+ ...shuffleProps(propositionsValid, nbValid),
186
+ ...shuffleProps(propositionsMandatory, nbMandatory),
187
+ ...shuffleProps(propositionsFiller, n - nbValid - nbMandatory),
188
+ ], n);
189
+ };
190
+ const createRandomIdentifiers = () => {
191
+ const poolNameList = ["l", "lst", "liste"];
192
+ const nameList = random(poolNameList);
193
+ const listInitial = (() => {
194
+ const length = randint(4, 7);
195
+ const poolNumber = [...Array(61).keys()].map((i) => i - 30);
196
+ const listNumber = randomMany(poolNumber, length);
197
+ return listNumber;
198
+ })();
199
+ const indexAsked = randint(1, listInitial.length - 1);
200
+ const identifiers = { nameList, listInitial, indexAsked };
201
+ return identifiers;
202
+ };
203
+ const getPyListCreateListInstructionCompletionQuestion = () => {
204
+ const identifiers = createRandomIdentifiers();
205
+ return getQuestionFromIdentifiers(identifiers);
206
+ };
207
+ const getQuestionFromIdentifiers = (identifiers, opts) => {
208
+ const question = {
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 pyListCreateListInstructionCompletion = {
220
+ id: "pyListCreateListInstructionCompletion",
221
+ label: "Créer une liste en Python (compléter le programme)",
222
+ isSingleStep: true,
223
+ generator: (nb, opts) => getDistinctQuestions(() => getPyListCreateListInstructionCompletionQuestion(opts), nb),
224
+ qcmTimer: 60,
225
+ freeTimer: 60,
226
+ getPropositions,
227
+ subject: "Mathématiques",
228
+ getQuestionFromIdentifiers,
229
+ hasHintAndCorrection: true,
230
+ answerType: "QCM",
231
+ isQCM: true,
232
+ };
@@ -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 pyListElemAtIndex: Exercise<Identifiers>;
8
+ export {};
9
+ //# sourceMappingURL=pyListElemAtIndex.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pyListElemAtIndex.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/python/list/pyListElemAtIndex.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAcT,MAAM,6BAA6B,CAAC;AA6BrC,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,OAAO,EAAE,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAkUF,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,WAAW,CAanD,CAAC"}
@@ -0,0 +1,292 @@
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 { 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 codify = (strPython) => {
8
+ return `\`\`\`python
9
+ ${strPython}
10
+ \`\`\``;
11
+ };
12
+ const codifyChunk = (strPython) => {
13
+ return `\`${strPython}\``;
14
+ };
15
+ const strPythonForList = (list) => {
16
+ return `[${list.map((elem) => strPythonForListElem(elem)).join(", ")}]`;
17
+ };
18
+ const strPythonForListElem = (elem) => {
19
+ if (typeof elem === "string") {
20
+ return `'${elem}'`;
21
+ }
22
+ else {
23
+ return `${elem}`;
24
+ }
25
+ };
26
+ const getStrPythonProgram = (identifiers) => {
27
+ const { nameList, listInitial, indexAsked } = identifiers;
28
+ return `${nameList} = ${strPythonForList(listInitial)}
29
+ print(${nameList}[${indexAsked}])
30
+ `;
31
+ };
32
+ const getFunctionForPythonProgram = (identifiers) => {
33
+ const { nameList, listInitial, indexAsked } = identifiers;
34
+ return (..._otherArgs) => {
35
+ const outDict = {};
36
+ //init
37
+ const list = listInitial;
38
+ outDict[0] = {
39
+ [nameList]: list,
40
+ };
41
+ //main
42
+ {
43
+ if (indexAsked >= 0) {
44
+ if (indexAsked < list.length) {
45
+ outDict[1] = {
46
+ [nameList]: list,
47
+ elem: list[indexAsked],
48
+ };
49
+ }
50
+ else {
51
+ outDict[1] = {
52
+ [nameList]: list,
53
+ err: "IndexError: list index out of range",
54
+ };
55
+ }
56
+ }
57
+ else {
58
+ if (indexAsked < -list.length) {
59
+ outDict[1] = {
60
+ [nameList]: list,
61
+ err: "IndexError: list index out of range",
62
+ };
63
+ }
64
+ else {
65
+ outDict[1] = {
66
+ [nameList]: list,
67
+ elem: list[list.length + indexAsked],
68
+ };
69
+ }
70
+ }
71
+ }
72
+ //convenience: store last step in -1
73
+ outDict[-1] = outDict[Math.max(...Object.keys(outDict).map((k) => +k))];
74
+ return outDict;
75
+ };
76
+ };
77
+ const getInstruction = (identifiers) => {
78
+ return `Qu'affichera le script en Python suivant ?
79
+
80
+ ${codify(getStrPythonProgram(identifiers))}
81
+
82
+ `;
83
+ };
84
+ const getAnswer = (identifiers) => {
85
+ const stepDictEnd = getFunctionForPythonProgram(identifiers)()[-1];
86
+ return `${stepDictEnd.elem ?? stepDictEnd.err}`;
87
+ };
88
+ const getHint = () => {
89
+ return `Nommons $n$ la longueur de la liste (autrement dit son nombre d'emplacements).
90
+
91
+ - Le premier élément est à l'indice $0$.
92
+ - Le dernier élément est à l'indice $n-1$.
93
+
94
+ On peut aussi récupérer les éléments en partant de la fin :
95
+
96
+ - Le dernier élément est à l'indice $-1$.
97
+ - Le premier élément est à l'indice $-n$.
98
+
99
+ Attention à ne pas demander un indice trop grand ou trop petit : cela provoquerait une erreur.`;
100
+ };
101
+ const getCorrection = (identifiers) => {
102
+ const { nameList, listInitial, indexAsked } = identifiers;
103
+ return `Dans le programme proposé, la dernière ligne est
104
+
105
+ ${codify(`print(${nameList}[${indexAsked}])`)}
106
+
107
+ On veut donc afficher l'élément de $${nameList}$ à l'indice $${indexAsked}$.
108
+
109
+ La taille de la liste est $${listInitial.length}$.
110
+
111
+ ${(() => {
112
+ if (indexAsked >= 0) {
113
+ return mdTable([
114
+ ["\\text{Indice}", ...listInitial.map((_, i) => `${i}`)],
115
+ [
116
+ "\\text{Valeur}",
117
+ ...listInitial.map((v) => `\\text{${strPythonForListElem(v)}}`),
118
+ ],
119
+ ], true);
120
+ }
121
+ else {
122
+ return mdTable([
123
+ [
124
+ "\\text{Indice}",
125
+ ...listInitial.map((_, i) => `${-listInitial.length + i}`),
126
+ ],
127
+ [
128
+ "\\text{Valeur}",
129
+ ...listInitial.map((v) => `\\text{${strPythonForListElem(v)}}`),
130
+ ],
131
+ ], true);
132
+ }
133
+ })()}
134
+
135
+ ${(() => {
136
+ if (indexAsked >= 0) {
137
+ if (indexAsked < listInitial.length) {
138
+ return `L'indice demandé est compris entre $0$ et $${listInitial.length - 1}$ inclus.
139
+
140
+ Le programme affichera :
141
+
142
+ ${codify(getAnswer(identifiers))}
143
+
144
+ `;
145
+ }
146
+ else {
147
+ return `L'indice demandé est strictement supérieur à $${listInitial.length - 1}$.
148
+
149
+ On a dépassé l'indice maximum permis.
150
+
151
+ Le programme affichera :
152
+
153
+ ${codify(getAnswer(identifiers))}
154
+
155
+ `;
156
+ }
157
+ }
158
+ else {
159
+ if (indexAsked < -listInitial.length) {
160
+ return `L'indice demandé est strictement inférieur à $${-listInitial.length}$.
161
+
162
+ On a dépassé l'indice mininum permis.
163
+
164
+ Le programme affichera :
165
+
166
+ ${codify(getAnswer(identifiers))}
167
+
168
+ `;
169
+ }
170
+ else {
171
+ return `L'indice demandé est compris entre $-1$ et $${-listInitial.length}$ inclus.
172
+
173
+ On récupère l'élément en partant de la fin.
174
+
175
+ Le programme affichera :
176
+
177
+ ${codify(getAnswer(identifiers))}
178
+
179
+ `;
180
+ }
181
+ }
182
+ })()}
183
+
184
+ `;
185
+ };
186
+ const getPropositions = (n, { answer, ...identifiers }) => {
187
+ const propositions = [];
188
+ addValidProp(propositions, codifyChunk(answer), "raw");
189
+ const { indexAsked } = identifiers;
190
+ //indexAsked-1
191
+ {
192
+ const identifiersWrong = Object.assign({}, identifiers, {
193
+ indexAsked: indexAsked - 1,
194
+ });
195
+ tryToAddWrongProp(propositions, codifyChunk(getAnswer(identifiersWrong)), "raw");
196
+ }
197
+ //indexAsked+1
198
+ {
199
+ const identifiersWrong = Object.assign({}, identifiers, {
200
+ indexAsked: indexAsked + 1,
201
+ });
202
+ tryToAddWrongProp(propositions, codifyChunk(getAnswer(identifiersWrong)), "raw");
203
+ }
204
+ //-indexAsked
205
+ {
206
+ const identifiersWrong = Object.assign({}, identifiers, {
207
+ indexAsked: -indexAsked,
208
+ });
209
+ tryToAddWrongProp(propositions, codifyChunk(getAnswer(identifiersWrong)), "raw");
210
+ }
211
+ //error
212
+ {
213
+ const identifiersWrong = Object.assign({}, identifiers, {
214
+ indexAsked: 404,
215
+ });
216
+ tryToAddWrongProp(propositions, codifyChunk(getAnswer(identifiersWrong)), "raw");
217
+ }
218
+ //filler
219
+ {
220
+ const { listInitial } = identifiers;
221
+ propWhile(propositions, n, () => {
222
+ const identifiersWrong = Object.assign({}, identifiers, {
223
+ indexAsked: randint(0, listInitial.length),
224
+ });
225
+ tryToAddWrongProp(propositions, codifyChunk(getAnswer(identifiersWrong)), "raw");
226
+ });
227
+ }
228
+ return shuffleProps(propositions, n);
229
+ };
230
+ const createRandomIdentifiers = () => {
231
+ const poolNameList = ["l", "lst", "liste"];
232
+ const nameList = random(poolNameList);
233
+ const listInitial = (() => {
234
+ const length = randint(4, 9);
235
+ const poolNumber = [...Array(61).keys()].map((i) => i - 30);
236
+ const listNumber = randomMany(poolNumber, length);
237
+ const poolLetter = "abcdefghijklmnopqrstuvwxyz".split("");
238
+ const listLetters = randomMany(poolLetter, length);
239
+ const rand = randint(0, 4);
240
+ switch (rand) {
241
+ case 0:
242
+ return listNumber;
243
+ case 1:
244
+ return listLetters;
245
+ case 2: {
246
+ return [...Array(length).keys()].map(() => {
247
+ const word = [...Array(randint(2, 5)).keys()]
248
+ .map(() => random(poolLetter))
249
+ .join("");
250
+ return word;
251
+ });
252
+ }
253
+ case 3:
254
+ return zip(listNumber, listLetters).map(([n, letter]) => random([n, letter]));
255
+ default:
256
+ throw new Error("Unsupported rand: " + rand);
257
+ }
258
+ })();
259
+ const indexAsked = randint(-8, 9);
260
+ const identifiers = { nameList, listInitial, indexAsked };
261
+ return identifiers;
262
+ };
263
+ const getPyListElemAtIndexQuestion = () => {
264
+ const identifiers = createRandomIdentifiers();
265
+ return getQuestionFromIdentifiers(identifiers);
266
+ };
267
+ const getQuestionFromIdentifiers = (identifiers, opts) => {
268
+ const question = {
269
+ answer: getAnswer(identifiers, opts),
270
+ instruction: getInstruction(identifiers, opts),
271
+ keys: [],
272
+ answerFormat: "tex",
273
+ identifiers,
274
+ hint: getHint(identifiers, opts),
275
+ correction: getCorrection(identifiers, opts),
276
+ options: opts,
277
+ };
278
+ return question;
279
+ };
280
+ export const pyListElemAtIndex = {
281
+ id: "pyListElemAtIndex",
282
+ label: "Lire un élément dans une liste en Python",
283
+ isSingleStep: true,
284
+ generator: (nb, opts) => getDistinctQuestions(() => getPyListElemAtIndexQuestion(opts), nb),
285
+ qcmTimer: 60,
286
+ freeTimer: 60,
287
+ getPropositions,
288
+ subject: "Mathématiques",
289
+ getQuestionFromIdentifiers,
290
+ hasHintAndCorrection: true,
291
+ answerType: "QCU",
292
+ };
@@ -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 pyListMutationMix: Exercise<Identifiers>;
28
+ export {};
29
+ //# sourceMappingURL=pyListMutationMix.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pyListMutationMix.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/python/list/pyListMutationMix.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAcT,MAAM,6BAA6B,CAAC;AAyIrC,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;AAsbF,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,WAAW,CAanD,CAAC"}