math-exercises 3.0.75 → 3.0.76
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.
- package/lib/exercises/math/calcul/arithmetics/calculateDistanceBetweenNumbers.d.ts +8 -0
- package/lib/exercises/math/calcul/arithmetics/calculateDistanceBetweenNumbers.d.ts.map +1 -0
- package/lib/exercises/math/calcul/arithmetics/calculateDistanceBetweenNumbers.js +102 -0
- package/lib/exercises/math/calcul/arithmetics/index.d.ts +1 -0
- package/lib/exercises/math/calcul/arithmetics/index.d.ts.map +1 -1
- package/lib/exercises/math/calcul/arithmetics/index.js +1 -0
- package/lib/exercises/math/calcul/sign/index.d.ts +1 -0
- package/lib/exercises/math/calcul/sign/index.d.ts.map +1 -1
- package/lib/exercises/math/calcul/sign/index.js +1 -0
- package/lib/exercises/math/calcul/sign/inverseOrOpposite.d.ts +8 -0
- package/lib/exercises/math/calcul/sign/inverseOrOpposite.d.ts.map +1 -0
- package/lib/exercises/math/calcul/sign/inverseOrOpposite.js +89 -0
- package/lib/exercises/math/functions/parity/parityFromGraph.d.ts.map +1 -1
- package/lib/exercises/math/functions/parity/parityFromGraph.js +16 -0
- package/lib/exercises/math/probaStat/probaFromTableNoContext.d.ts.map +1 -1
- package/lib/exercises/math/probaStat/probaFromTableNoContext.js +1 -1
- package/lib/exercises/math/probaStat/probaFromTableWithContext.js +87 -127
- package/lib/exercises/math/python/conditionIf.d.ts.map +1 -1
- package/lib/exercises/math/python/conditionIf.js +32 -1
- package/lib/exercises/math/python/conditionIfElse.d.ts +10 -0
- package/lib/exercises/math/python/conditionIfElse.d.ts.map +1 -0
- package/lib/exercises/math/python/conditionIfElse.js +119 -0
- package/lib/exercises/math/python/forLoop.d.ts.map +1 -1
- package/lib/exercises/math/python/forLoop.js +28 -0
- package/lib/exercises/math/python/inOutCalcul.d.ts.map +1 -1
- package/lib/exercises/math/python/inOutCalcul.js +31 -4
- package/lib/exercises/math/python/index.d.ts +2 -0
- package/lib/exercises/math/python/index.d.ts.map +1 -1
- package/lib/exercises/math/python/index.js +2 -0
- package/lib/exercises/math/python/pyForLoop1Exercise.d.ts.map +1 -1
- package/lib/exercises/math/python/pyForLoop1Exercise.js +29 -0
- package/lib/exercises/math/python/pyWhileLoop1Exercise.d.ts.map +1 -1
- package/lib/exercises/math/python/pyWhileLoop1Exercise.js +1 -0
- package/lib/exercises/math/python/pythonFunctionTrinom.js +1 -1
- package/lib/exercises/math/python/variableAffectation.d.ts +10 -0
- package/lib/exercises/math/python/variableAffectation.d.ts.map +1 -0
- package/lib/exercises/math/python/variableAffectation.js +144 -0
- package/lib/exercises/math/python/whileLoop.d.ts +0 -1
- package/lib/exercises/math/python/whileLoop.d.ts.map +1 -1
- package/lib/exercises/math/python/whileLoop.js +37 -6
- package/lib/exercises/math/python/whileLoopCount.js +2 -2
- package/lib/index.d.ts +15 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/latexTester.js +1 -0
- package/lib/math/polynomials/affine.d.ts +2 -1
- package/lib/math/polynomials/affine.d.ts.map +1 -1
- package/lib/math/polynomials/affine.js +5 -2
- package/lib/tree/nodes/functions/oppositeNode.d.ts +2 -2
- package/lib/tree/nodes/functions/oppositeNode.d.ts.map +1 -1
- package/lib/tree/nodes/functions/oppositeNode.js +4 -2
- package/lib/tree/nodes/node.d.ts +2 -0
- package/lib/tree/nodes/node.d.ts.map +1 -1
- package/lib/tree/nodes/operators/fractionNode.d.ts.map +1 -1
- package/lib/tree/nodes/operators/fractionNode.js +8 -7
- package/package.json +1 -1
|
@@ -0,0 +1,119 @@
|
|
|
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 { coinFlip } from "../../../utils/alea/coinFlip.js";
|
|
5
|
+
import { random } from "../../../utils/alea/random.js";
|
|
6
|
+
const operations = [
|
|
7
|
+
{ name: "+", func: (x, step) => x + step },
|
|
8
|
+
{ name: "-", func: (x, step) => x - step },
|
|
9
|
+
{ name: "*", func: (x, step) => x * step },
|
|
10
|
+
{ name: "//", func: (x, step) => Math.floor(x / step) },
|
|
11
|
+
];
|
|
12
|
+
const getAnswer = (identifiers) => {
|
|
13
|
+
const { a, b, opName, condition } = identifiers;
|
|
14
|
+
const operation = operations.find((op) => op.name === opName);
|
|
15
|
+
const opresult = operation.func(a, b);
|
|
16
|
+
const answer = (condition === "a <= b" ? opresult <= b : opresult >= b)
|
|
17
|
+
? b
|
|
18
|
+
: opresult + 1;
|
|
19
|
+
return answer.frenchify();
|
|
20
|
+
};
|
|
21
|
+
const getInstruction = (identifiers) => {
|
|
22
|
+
const { a, b, opName, condition } = identifiers;
|
|
23
|
+
return `Quel sera l'affichage du script en Python suivant ?
|
|
24
|
+
\`\`\`python
|
|
25
|
+
a = ${a}
|
|
26
|
+
b = ${b}
|
|
27
|
+
a = a ${opName} b
|
|
28
|
+
if ${condition} :
|
|
29
|
+
a = b
|
|
30
|
+
else :
|
|
31
|
+
a = a + 1
|
|
32
|
+
print(a)
|
|
33
|
+
\`\`\`
|
|
34
|
+
`;
|
|
35
|
+
};
|
|
36
|
+
const getHint = (identifiers) => {
|
|
37
|
+
const { opName, condition } = identifiers;
|
|
38
|
+
return `Calcule la valeur de $a$ après l'exécution de l'instruction $a = a ${opName} b$.
|
|
39
|
+
|
|
40
|
+
Ensuite, vérifie si la condition $${condition}$ est vraie ou fausse.`;
|
|
41
|
+
};
|
|
42
|
+
const getCorrection = (identifiers) => {
|
|
43
|
+
const { a, b, opName, condition } = identifiers;
|
|
44
|
+
const operation = operations.find((op) => op.name === opName);
|
|
45
|
+
const opresult = operation.func(a, b);
|
|
46
|
+
const finalValue = (condition === "a <= b" ? opresult <= b : opresult >= b)
|
|
47
|
+
? b
|
|
48
|
+
: opresult + 1;
|
|
49
|
+
const branch = condition === "a <= b" ? opresult <= b : opresult >= b;
|
|
50
|
+
const branchText = branch
|
|
51
|
+
? `La condition $${condition}$ est donc vraie. On exécute alors le bloc \`if\` donc : $a = ${b}$.`
|
|
52
|
+
: `La condition $${condition}$ est donc fausse. On exécute alors le bloc \`else\` donc :
|
|
53
|
+
|
|
54
|
+
$$
|
|
55
|
+
a = ${opresult} + 1 = ${opresult + 1}
|
|
56
|
+
$$`;
|
|
57
|
+
return `On calcule l'opération $a ${opName} b$ :
|
|
58
|
+
|
|
59
|
+
$$
|
|
60
|
+
${a} ${opName} ${b} = ${opresult}
|
|
61
|
+
$$
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
${branchText}
|
|
65
|
+
|
|
66
|
+
Le résultat final affiché sera : $${finalValue}$.`;
|
|
67
|
+
};
|
|
68
|
+
const getConditionIfElseQuestion = () => {
|
|
69
|
+
const a = randint(0, 10, [0, 1]);
|
|
70
|
+
const b = randint(0, 10, [0, 1]);
|
|
71
|
+
const operation = random(operations);
|
|
72
|
+
const condition = coinFlip() ? "a <= b" : "b <= a";
|
|
73
|
+
const identifiers = { a, b, opName: operation.name, condition };
|
|
74
|
+
return getQuestionFromIdentifiers(identifiers);
|
|
75
|
+
};
|
|
76
|
+
const getQuestionFromIdentifiers = (identifiers) => {
|
|
77
|
+
const question = {
|
|
78
|
+
answer: getAnswer(identifiers),
|
|
79
|
+
hint: getHint(identifiers),
|
|
80
|
+
correction: getCorrection(identifiers),
|
|
81
|
+
instruction: getInstruction(identifiers),
|
|
82
|
+
keys: ["a", "b", "equal"],
|
|
83
|
+
answerFormat: "tex",
|
|
84
|
+
identifiers,
|
|
85
|
+
};
|
|
86
|
+
return question;
|
|
87
|
+
};
|
|
88
|
+
const getPropositions = (n, { answer, a, b, opName }) => {
|
|
89
|
+
const propositions = [];
|
|
90
|
+
const operation = operations.find((op) => op.name === opName);
|
|
91
|
+
const opresult = operation.func(a, b);
|
|
92
|
+
const elseResult = opresult + 1;
|
|
93
|
+
addValidProp(propositions, answer);
|
|
94
|
+
tryToAddWrongProp(propositions, a.frenchify());
|
|
95
|
+
tryToAddWrongProp(propositions, b.frenchify());
|
|
96
|
+
tryToAddWrongProp(propositions, opresult.frenchify());
|
|
97
|
+
tryToAddWrongProp(propositions, elseResult.frenchify());
|
|
98
|
+
while (propositions.length < n) {
|
|
99
|
+
tryToAddWrongProp(propositions, randint(0, 10).frenchify());
|
|
100
|
+
}
|
|
101
|
+
return shuffleProps(propositions, n);
|
|
102
|
+
};
|
|
103
|
+
const isAnswerValid = (ans, { answer }) => {
|
|
104
|
+
return ans === answer;
|
|
105
|
+
};
|
|
106
|
+
export const conditionIfElse = {
|
|
107
|
+
id: "conditionIfElse",
|
|
108
|
+
label: "Condition if-else",
|
|
109
|
+
isSingleStep: true,
|
|
110
|
+
generator: (nb) => getDistinctQuestions(getConditionIfElseQuestion, nb),
|
|
111
|
+
qcmTimer: 60,
|
|
112
|
+
freeTimer: 60,
|
|
113
|
+
getPropositions,
|
|
114
|
+
getHint,
|
|
115
|
+
isAnswerValid,
|
|
116
|
+
subject: "Mathématiques",
|
|
117
|
+
getQuestionFromIdentifiers,
|
|
118
|
+
hasHintAndCorrection: true,
|
|
119
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"forLoop.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/python/forLoop.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,
|
|
1
|
+
{"version":3,"file":"forLoop.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/python/forLoop.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAcT,MAAM,6BAA6B,CAAC;AAIrC,KAAK,WAAW,GAAG;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAsIF,eAAO,MAAM,OAAO,EAAE,QAAQ,CAAC,WAAW,CAYzC,CAAC"}
|
|
@@ -29,6 +29,31 @@ const getAnswer = (identifiers) => {
|
|
|
29
29
|
const answer = value.toString();
|
|
30
30
|
return answer;
|
|
31
31
|
};
|
|
32
|
+
const getHint = (identifiers) => {
|
|
33
|
+
return `L'instruction \`for i in range(a,b)\` est une boucle dans laquelle $i$ prend d'abord la valeur $a$, puis augmente de $1$ jusqu'à atteindre $b$ (exclus). `;
|
|
34
|
+
};
|
|
35
|
+
const getCorrection = (identifiers) => {
|
|
36
|
+
const { initialValue, step, iterations, opIndex } = identifiers;
|
|
37
|
+
const op = operations[opIndex];
|
|
38
|
+
let allValues = [];
|
|
39
|
+
let n = initialValue;
|
|
40
|
+
for (let i = 0; i < iterations; i++) {
|
|
41
|
+
allValues.push(n.frenchify());
|
|
42
|
+
n = op.func(n, step);
|
|
43
|
+
}
|
|
44
|
+
allValues.push(n.frenchify());
|
|
45
|
+
return `La boucle \`for\` s'éxécute $${iterations}$ fois, car $i$ prend les valeurs de $0$ à $${iterations - 1}$.
|
|
46
|
+
|
|
47
|
+
À chaque itération, $x$ prend la valeur $x ${op.name} ${step}$.
|
|
48
|
+
|
|
49
|
+
$x$ prend donc les valeurs successives suivantes :
|
|
50
|
+
|
|
51
|
+
$$
|
|
52
|
+
${allValues.join("\\rightarrow ")}
|
|
53
|
+
$$
|
|
54
|
+
|
|
55
|
+
Le programme affichera donc $${n.frenchify()}$.`;
|
|
56
|
+
};
|
|
32
57
|
const getForLoopQuestion = () => {
|
|
33
58
|
const initialValue = randint(-10, 10, [0, 1]);
|
|
34
59
|
const opIndex = randint(0, operations.length);
|
|
@@ -44,6 +69,8 @@ const getQuestionFromIdentifiers = (identifiers) => {
|
|
|
44
69
|
keys: ["a", "equal"],
|
|
45
70
|
answerFormat: "tex",
|
|
46
71
|
identifiers,
|
|
72
|
+
hint: getHint(identifiers),
|
|
73
|
+
correction: getCorrection(identifiers),
|
|
47
74
|
};
|
|
48
75
|
return question;
|
|
49
76
|
};
|
|
@@ -96,4 +123,5 @@ export const forLoop = {
|
|
|
96
123
|
isAnswerValid,
|
|
97
124
|
subject: "Mathématiques",
|
|
98
125
|
getQuestionFromIdentifiers,
|
|
126
|
+
hasHintAndCorrection: true,
|
|
99
127
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inOutCalcul.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/python/inOutCalcul.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,
|
|
1
|
+
{"version":3,"file":"inOutCalcul.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/python/inOutCalcul.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAcT,MAAM,6BAA6B,CAAC;AAIrC,KAAK,WAAW,GAAG;IACjB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAoHF,eAAO,MAAM,WAAW,EAAE,QAAQ,CAAC,WAAW,CAY7C,CAAC"}
|
|
@@ -30,11 +30,35 @@ print(a)
|
|
|
30
30
|
\`\`\`
|
|
31
31
|
`;
|
|
32
32
|
};
|
|
33
|
+
const getHint = (identifiers) => {
|
|
34
|
+
const { a, b, id1, id2 } = identifiers;
|
|
35
|
+
return `Suis le script ligne par ligne, en remplaçant les variables par les valeurs qu'elles ont prises aux lignes précédentes.`;
|
|
36
|
+
};
|
|
37
|
+
const getCorrection = (identifiers) => {
|
|
38
|
+
const { a, b, id1, id2 } = identifiers;
|
|
39
|
+
const op1 = operations[id1];
|
|
40
|
+
const op2 = operations[id2];
|
|
41
|
+
const interB = op1.func(a, b);
|
|
42
|
+
return `On détaille ligne par ligne le script :
|
|
43
|
+
|
|
44
|
+
\`\`\`
|
|
45
|
+
a = ${a}
|
|
46
|
+
b = ${b}
|
|
47
|
+
b = a ${op1.name} b # Ici b prend la valeur ${a} ${op1.name} ${b} = ${interB}
|
|
48
|
+
a = a ${op2.name} b # Ici, la valeur de b est ${interB}, donc a prend la valeur ${a} ${op2.name} ${interB} = ${op2.func(a, interB)}
|
|
49
|
+
print(a)
|
|
50
|
+
\`\`\`
|
|
51
|
+
L'affichage à la fin du script est donc $${op2.func(a, interB)}$.
|
|
52
|
+
`;
|
|
53
|
+
};
|
|
33
54
|
const getInOutCalculQuestion = () => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
55
|
+
let a = randint(-10, 10);
|
|
56
|
+
let b = randint(-10, 10, [0]);
|
|
57
|
+
let id1 = randint(0, operations.length);
|
|
58
|
+
let id2 = randint(0, operations.length);
|
|
59
|
+
while (id2 === 3 && operations[id1].func(a, b) === 0) {
|
|
60
|
+
id2 = randint(0, operations.length);
|
|
61
|
+
}
|
|
38
62
|
const identifiers = { a, b, id1, id2 };
|
|
39
63
|
return getQuestionFromIdentifiers(identifiers);
|
|
40
64
|
};
|
|
@@ -45,6 +69,8 @@ const getQuestionFromIdentifiers = (identifiers) => {
|
|
|
45
69
|
keys: ["a", "b", "equal"],
|
|
46
70
|
answerFormat: "tex",
|
|
47
71
|
identifiers,
|
|
72
|
+
hint: getHint(identifiers),
|
|
73
|
+
correction: getCorrection(identifiers),
|
|
48
74
|
};
|
|
49
75
|
return question;
|
|
50
76
|
};
|
|
@@ -78,4 +104,5 @@ export const inOutCalcul = {
|
|
|
78
104
|
isAnswerValid,
|
|
79
105
|
subject: "Mathématiques",
|
|
80
106
|
getQuestionFromIdentifiers,
|
|
107
|
+
hasHintAndCorrection: true,
|
|
81
108
|
};
|
|
@@ -9,4 +9,6 @@ export * from "./pyNestedForLoopExercise.js";
|
|
|
9
9
|
export * from "./pyIfElseCondition.js";
|
|
10
10
|
export * from "./variableType.js";
|
|
11
11
|
export * from "./whileLoopCount.js";
|
|
12
|
+
export * from "./conditionIfElse.js";
|
|
13
|
+
export * from "./variableAffectation.js";
|
|
12
14
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/python/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/python/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pyForLoop1Exercise.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/python/pyForLoop1Exercise.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,
|
|
1
|
+
{"version":3,"file":"pyForLoop1Exercise.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/python/pyForLoop1Exercise.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAcT,MAAM,6BAA6B,CAAC;AAIrC,KAAK,WAAW,GAAG;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAuIF,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAAC,WAAW,CAYxD,CAAC"}
|
|
@@ -38,6 +38,32 @@ const getForLoopQuestion = () => {
|
|
|
38
38
|
const identifiers = { initialValue, step, iterations, opIndex };
|
|
39
39
|
return getQuestionFromIdentifiers(identifiers);
|
|
40
40
|
};
|
|
41
|
+
const getHint = (identifiers) => {
|
|
42
|
+
const { initialValue, step, iterations, opIndex } = identifiers;
|
|
43
|
+
return `La valeur entrée par l'utilisateur va être affectée à la variable $y$. La boucle \`for\` s'exécute pour $i$ allant de $1$ à $${iterations}$.`;
|
|
44
|
+
};
|
|
45
|
+
const getCorrection = (identifiers) => {
|
|
46
|
+
const { initialValue, step, iterations, opIndex } = identifiers;
|
|
47
|
+
const op = operations[opIndex];
|
|
48
|
+
let allValues = [];
|
|
49
|
+
let n = initialValue;
|
|
50
|
+
for (let i = 0; i < iterations; i++) {
|
|
51
|
+
allValues.push(n.frenchify());
|
|
52
|
+
n = op.func(n, step);
|
|
53
|
+
}
|
|
54
|
+
allValues.push(n.frenchify());
|
|
55
|
+
return `Puisque l'utilisateur entre la valeur $${step}$, y vaut $${step}$. La boucle \`for\` s'éxécute $${iterations}$ fois, car $i$ prend les valeurs de $1$ à $${iterations}$.
|
|
56
|
+
|
|
57
|
+
À chaque itération, $x$ prend la valeur $x ${op.name} ${step}$.
|
|
58
|
+
|
|
59
|
+
$x$ prend donc les valeurs successives suivantes :
|
|
60
|
+
|
|
61
|
+
$$
|
|
62
|
+
${allValues.join("\\rightarrow ")}
|
|
63
|
+
$$
|
|
64
|
+
|
|
65
|
+
Le programme affichera donc $${n.frenchify()}$.`;
|
|
66
|
+
};
|
|
41
67
|
const getQuestionFromIdentifiers = (identifiers) => {
|
|
42
68
|
const question = {
|
|
43
69
|
answer: getAnswer(identifiers),
|
|
@@ -45,6 +71,8 @@ const getQuestionFromIdentifiers = (identifiers) => {
|
|
|
45
71
|
keys: ["a", "equal"],
|
|
46
72
|
answerFormat: "tex",
|
|
47
73
|
identifiers,
|
|
74
|
+
hint: getHint(identifiers),
|
|
75
|
+
correction: getCorrection(identifiers),
|
|
48
76
|
};
|
|
49
77
|
return question;
|
|
50
78
|
};
|
|
@@ -97,4 +125,5 @@ export const pythonForLoop1Exercise = {
|
|
|
97
125
|
isAnswerValid,
|
|
98
126
|
subject: "Mathématiques",
|
|
99
127
|
getQuestionFromIdentifiers,
|
|
128
|
+
hasHintAndCorrection: true,
|
|
100
129
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pyWhileLoop1Exercise.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/python/pyWhileLoop1Exercise.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,6BAA6B,CAAC;AAQrC,KAAK,WAAW,GAAG;IACjB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,OAAO,CAAC;CAGpB,CAAC;AAyGF,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,WAAW,
|
|
1
|
+
{"version":3,"file":"pyWhileLoop1Exercise.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/python/pyWhileLoop1Exercise.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,6BAA6B,CAAC;AAQrC,KAAK,WAAW,GAAG;IACjB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,OAAO,CAAC;CAGpB,CAAC;AAyGF,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,WAAW,CActD,CAAC"}
|
|
@@ -61,7 +61,7 @@ const isAnswerValid = (ans, { answer }) => {
|
|
|
61
61
|
};
|
|
62
62
|
export const pythonFunctionTrinom = {
|
|
63
63
|
id: "pythonFunctionTrinom",
|
|
64
|
-
label: "Valeur de retour d'une fonction",
|
|
64
|
+
label: "Valeur de retour d'une fonction en Python",
|
|
65
65
|
isSingleStep: true,
|
|
66
66
|
generator: (nb) => getDistinctQuestions(getPythonFunctionTrinomQuestion, nb),
|
|
67
67
|
qcmTimer: 60,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Exercise } from "../../../exercises/exercise.js";
|
|
2
|
+
import { Affine } from "../../../math/polynomials/affine.js";
|
|
3
|
+
type Identifiers = {
|
|
4
|
+
variableName: string;
|
|
5
|
+
initialVariable: number;
|
|
6
|
+
affines: Affine[];
|
|
7
|
+
};
|
|
8
|
+
export declare const variableAffectation: Exercise<Identifiers>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=variableAffectation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variableAffectation.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/python/variableAffectation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAcT,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,MAAM,EAAqB,MAAM,kCAAkC,CAAC;AAQ7E,KAAK,WAAW,GAAG;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB,CAAC;AAwJF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,WAAW,CAiBrD,CAAC"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { addValidProp, shuffleProps, tryToAddWrongProp, } from "../../../exercises/exercise.js";
|
|
2
|
+
import { getDistinctQuestions } from "../../../exercises/utils/getDistinctQuestions.js";
|
|
3
|
+
import { Affine, AffineConstructor } from "../../../math/polynomials/affine.js";
|
|
4
|
+
import { randint } from "../../../math/utils/random/randint.js";
|
|
5
|
+
import { add } from "../../../tree/nodes/operators/addNode.js";
|
|
6
|
+
import { multiply } from "../../../tree/nodes/operators/multiplyNode.js";
|
|
7
|
+
import { random } from "../../../utils/alea/random.js";
|
|
8
|
+
import { handleVEAError } from "../../../utils/errors/handleVEAError.js";
|
|
9
|
+
const getPropositions = (n, { answer, initialVariable, affines }) => {
|
|
10
|
+
const propositions = [];
|
|
11
|
+
addValidProp(propositions, answer);
|
|
12
|
+
tryToAddWrongProp(propositions, `${initialVariable}`);
|
|
13
|
+
let variable = initialVariable;
|
|
14
|
+
for (const affine of affines) {
|
|
15
|
+
variable = affine.calculate(variable);
|
|
16
|
+
tryToAddWrongProp(propositions, `${variable}`);
|
|
17
|
+
tryToAddWrongProp(propositions, `${add(variable, 1).simplify().toTex()}`);
|
|
18
|
+
tryToAddWrongProp(propositions, `${add(variable, -1).simplify().toTex()}`);
|
|
19
|
+
tryToAddWrongProp(propositions, `${multiply(variable, -1).simplify().toTex()}`);
|
|
20
|
+
}
|
|
21
|
+
return shuffleProps(propositions, n);
|
|
22
|
+
};
|
|
23
|
+
const getAnswer = (identifiers) => {
|
|
24
|
+
const { initialVariable, affines } = identifiers;
|
|
25
|
+
let variable = initialVariable;
|
|
26
|
+
for (const affine of affines) {
|
|
27
|
+
variable = affine.calculate(variable);
|
|
28
|
+
}
|
|
29
|
+
return `${variable}`;
|
|
30
|
+
};
|
|
31
|
+
const getInstruction = (identifiers) => {
|
|
32
|
+
const { variableName, initialVariable, affines } = identifiers;
|
|
33
|
+
const affinePythonStrings = affines
|
|
34
|
+
.map((a) => a.toPython())
|
|
35
|
+
.join(`;\n${variableName} = `);
|
|
36
|
+
return `On exécute le script Python ci-dessous. Quelle est la valeur de \`${variableName}\` à la fin du script ?
|
|
37
|
+
|
|
38
|
+
\`\`\`
|
|
39
|
+
${variableName} = ${initialVariable};
|
|
40
|
+
${variableName} = ${affinePythonStrings};
|
|
41
|
+
\`\`\`
|
|
42
|
+
`;
|
|
43
|
+
};
|
|
44
|
+
const getHint = (identifiers) => {
|
|
45
|
+
const { variableName } = identifiers;
|
|
46
|
+
return `Pour chaque ligne, calcule la nouvelle valeur de \`${variableName}\`.`;
|
|
47
|
+
};
|
|
48
|
+
const getCorrection = (identifiers) => {
|
|
49
|
+
const { variableName, initialVariable, affines } = identifiers;
|
|
50
|
+
let variable = initialVariable;
|
|
51
|
+
let evVariable;
|
|
52
|
+
return `Pour chaque ligne, on calcule la valeur de l'expression à droite,
|
|
53
|
+
et on affecte cette valeur dans la variable \`${variableName}\`. On a donc :
|
|
54
|
+
|
|
55
|
+
\`\`\`
|
|
56
|
+
${variableName} = ${initialVariable}; # Ici ${variableName} = ${variable}
|
|
57
|
+
${affines
|
|
58
|
+
.map((a) => {
|
|
59
|
+
evVariable = a
|
|
60
|
+
.toTree()
|
|
61
|
+
.toDetailedEvaluation({ [variableName]: variable.toTree() });
|
|
62
|
+
variable = a.calculate(variable);
|
|
63
|
+
return (`${variableName} = ` +
|
|
64
|
+
a.toPython() +
|
|
65
|
+
`; # Ici ${variableName} = ${evVariable
|
|
66
|
+
.toTex()
|
|
67
|
+
.replace("\\times", "*")
|
|
68
|
+
.replaceAll("\\left", "")
|
|
69
|
+
.replaceAll("\\right", "")} = ${variable}\n`);
|
|
70
|
+
})
|
|
71
|
+
.join("")}
|
|
72
|
+
\`\`\`
|
|
73
|
+
|
|
74
|
+
À la fin du script, \`${variableName}\` vaut donc $${variable}$.
|
|
75
|
+
`;
|
|
76
|
+
};
|
|
77
|
+
const isAnswerValid = (ans, { answer }) => {
|
|
78
|
+
try {
|
|
79
|
+
return ans === answer;
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
return handleVEAError(err);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const getVariableAffectationQuestion = (ops) => {
|
|
86
|
+
const variableNames = [
|
|
87
|
+
"v",
|
|
88
|
+
"var",
|
|
89
|
+
"x",
|
|
90
|
+
"y",
|
|
91
|
+
"z",
|
|
92
|
+
"t",
|
|
93
|
+
"toto",
|
|
94
|
+
"tata",
|
|
95
|
+
"foo",
|
|
96
|
+
"bar",
|
|
97
|
+
];
|
|
98
|
+
const variableName = random(variableNames);
|
|
99
|
+
const initialVariable = randint(-3, 3);
|
|
100
|
+
const numberOfLinesToGenerate = randint(1, 4);
|
|
101
|
+
let affines = [];
|
|
102
|
+
for (let i = 0; i < numberOfLinesToGenerate; i++) {
|
|
103
|
+
const type = randint(1, 4);
|
|
104
|
+
if (type === 1) {
|
|
105
|
+
affines.push(new Affine(1, randint(-4, 5, [0]), variableName));
|
|
106
|
+
}
|
|
107
|
+
else if (type === 2) {
|
|
108
|
+
affines.push(new Affine(randint(-4, 5, [0]), 0, variableName));
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
affines.push(AffineConstructor.random({ min: -4, max: 4 }, { min: -5, max: 5 }, variableName));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const identifiers = { variableName, initialVariable, affines };
|
|
115
|
+
return getQuestionFromIdentifiers(identifiers);
|
|
116
|
+
};
|
|
117
|
+
const getQuestionFromIdentifiers = (identifiers) => {
|
|
118
|
+
return {
|
|
119
|
+
answer: getAnswer(identifiers),
|
|
120
|
+
instruction: getInstruction(identifiers),
|
|
121
|
+
keys: [],
|
|
122
|
+
answerFormat: "tex",
|
|
123
|
+
identifiers,
|
|
124
|
+
hint: getHint(identifiers),
|
|
125
|
+
correction: getCorrection(identifiers),
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
export const variableAffectation = {
|
|
129
|
+
id: "variableAffectation",
|
|
130
|
+
label: "Affectation de variable et calculs simples",
|
|
131
|
+
isSingleStep: true,
|
|
132
|
+
generator: (nb, opts) => getDistinctQuestions(() => getVariableAffectationQuestion(opts), nb),
|
|
133
|
+
qcmTimer: 60,
|
|
134
|
+
freeTimer: 60,
|
|
135
|
+
getPropositions,
|
|
136
|
+
isAnswerValid,
|
|
137
|
+
subject: "Mathématiques",
|
|
138
|
+
getInstruction,
|
|
139
|
+
getHint,
|
|
140
|
+
getCorrection,
|
|
141
|
+
getAnswer,
|
|
142
|
+
getQuestionFromIdentifiers,
|
|
143
|
+
hasHintAndCorrection: true,
|
|
144
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"whileLoop.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/python/whileLoop.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,
|
|
1
|
+
{"version":3,"file":"whileLoop.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/python/whileLoop.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAcT,MAAM,6BAA6B,CAAC;AAIrC,KAAK,WAAW,GAAG;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX,CAAC;AAgIF,eAAO,MAAM,SAAS,EAAE,QAAQ,CAAC,WAAW,CAY3C,CAAC"}
|
|
@@ -10,14 +10,14 @@ const operationsreversed = [
|
|
|
10
10
|
{ name: "/", func: (x, step) => Math.floor(x / step) },
|
|
11
11
|
];
|
|
12
12
|
const getAnswer = (identifiers) => {
|
|
13
|
-
const { a, initialValue,
|
|
13
|
+
const { a, initialValue, opIndex, step, x } = identifiers;
|
|
14
14
|
const answer = x.toString();
|
|
15
15
|
return answer;
|
|
16
16
|
};
|
|
17
17
|
const getInstruction = (identifiers) => {
|
|
18
|
-
const { a, initialValue,
|
|
18
|
+
const { a, initialValue, opIndex, step, x } = identifiers;
|
|
19
19
|
const op = operations[opIndex];
|
|
20
|
-
return `Qu'affichera le programme suivant
|
|
20
|
+
return `Qu'affichera le programme suivant ?
|
|
21
21
|
\`\`\`
|
|
22
22
|
a = ${a}
|
|
23
23
|
n = ${initialValue}
|
|
@@ -27,6 +27,35 @@ print(n)
|
|
|
27
27
|
\`\`\`
|
|
28
28
|
`;
|
|
29
29
|
};
|
|
30
|
+
const getHint = (identifiers) => {
|
|
31
|
+
const { a, initialValue, opIndex, step, x } = identifiers;
|
|
32
|
+
const op = operations[opIndex];
|
|
33
|
+
return `La boucle s'exécute tant que la condition $n \\leq ${a}$ est vraie. À chaque itération, $n$ devient égal à $n ${op.name} ${step}$.`;
|
|
34
|
+
};
|
|
35
|
+
const getCorrection = (identifiers) => {
|
|
36
|
+
const { a, initialValue, opIndex, step } = identifiers;
|
|
37
|
+
const op = operations[opIndex];
|
|
38
|
+
let n = initialValue;
|
|
39
|
+
let count = 0;
|
|
40
|
+
let allValues = [];
|
|
41
|
+
while (n <= a) {
|
|
42
|
+
allValues.push(n.frenchify());
|
|
43
|
+
n = op.func(n, step);
|
|
44
|
+
count++;
|
|
45
|
+
}
|
|
46
|
+
allValues.push(n.frenchify());
|
|
47
|
+
return `On commence avec $n = ${initialValue}$ et à chaque itération on effectue l'opération $n = n ${op.name} ${step}$. La boucle while $n \\leq a$ s'exécute tant que $n$ est inférieur ou égal à $${a}$.
|
|
48
|
+
|
|
49
|
+
$n$ prend donc les valeurs successives suivantes :
|
|
50
|
+
|
|
51
|
+
$$
|
|
52
|
+
${allValues.join("\\rightarrow ")}
|
|
53
|
+
$$
|
|
54
|
+
|
|
55
|
+
La boucle s'arrêtte alors car $${allValues[allValues.length - 1]} > ${a}$.
|
|
56
|
+
|
|
57
|
+
Le programme affichera donc $${n.frenchify()}$.`;
|
|
58
|
+
};
|
|
30
59
|
const getQuestionFromIdentifiers = (identifiers) => {
|
|
31
60
|
const question = {
|
|
32
61
|
answer: getAnswer(identifiers),
|
|
@@ -34,6 +63,8 @@ const getQuestionFromIdentifiers = (identifiers) => {
|
|
|
34
63
|
keys: ["a", "equal"],
|
|
35
64
|
answerFormat: "tex",
|
|
36
65
|
identifiers,
|
|
66
|
+
hint: getHint(identifiers),
|
|
67
|
+
correction: getCorrection(identifiers),
|
|
37
68
|
};
|
|
38
69
|
return question;
|
|
39
70
|
};
|
|
@@ -42,13 +73,12 @@ const getWhileLoopQuestion = () => {
|
|
|
42
73
|
const opIndex = randint(0, operations.length);
|
|
43
74
|
const op = operations[opIndex];
|
|
44
75
|
const step = randint(1, 10, [0, 1]);
|
|
45
|
-
const iterations = randint(1, 6, [1]);
|
|
46
76
|
let x = initialValue;
|
|
47
77
|
const a = randint(10, 30);
|
|
48
78
|
while (x <= a) {
|
|
49
79
|
x = op.func(x, step);
|
|
50
80
|
}
|
|
51
|
-
const identifiers = { initialValue, step,
|
|
81
|
+
const identifiers = { initialValue, step, opIndex, a, x };
|
|
52
82
|
return getQuestionFromIdentifiers(identifiers);
|
|
53
83
|
};
|
|
54
84
|
const getPropositions = (n, { answer, step, opIndex, x }) => {
|
|
@@ -75,7 +105,7 @@ const isAnswerValid = (ans, { answer }) => {
|
|
|
75
105
|
};
|
|
76
106
|
export const whileLoop = {
|
|
77
107
|
id: "whileLoop",
|
|
78
|
-
label: "Boucle while $2$",
|
|
108
|
+
label: "Boucle while $2$ (Python)",
|
|
79
109
|
isSingleStep: true,
|
|
80
110
|
generator: (nb) => getDistinctQuestions(getWhileLoopQuestion, nb),
|
|
81
111
|
qcmTimer: 60,
|
|
@@ -84,4 +114,5 @@ export const whileLoop = {
|
|
|
84
114
|
isAnswerValid,
|
|
85
115
|
subject: "Mathématiques",
|
|
86
116
|
getQuestionFromIdentifiers,
|
|
117
|
+
hasHintAndCorrection: true,
|
|
87
118
|
};
|
|
@@ -23,7 +23,7 @@ const getAnswer = ({ inputValue, threshold }) => {
|
|
|
23
23
|
return count.frenchify();
|
|
24
24
|
};
|
|
25
25
|
const getHint = ({ inputValue, threshold }) => {
|
|
26
|
-
return `La boucle s'exécute tant que la condition $x > ${threshold}$ est vraie. À chaque
|
|
26
|
+
return `La boucle s'exécute tant que la condition $x > ${threshold}$ est vraie. À chaque itération, $x$ est divisé par $2$. Compte combien de fois on peut diviser $${inputValue}$ par $2$ avant d'obtenir un résultat inférieur ou égal à $${threshold}$.`;
|
|
27
27
|
};
|
|
28
28
|
const getCorrection = ({ inputValue, threshold, }) => {
|
|
29
29
|
let x = inputValue;
|
|
@@ -78,7 +78,7 @@ const getPropositions = (n, { answer, inputValue, threshold }) => {
|
|
|
78
78
|
const isAnswerValid = (ans, { answer }) => ans === answer;
|
|
79
79
|
export const pyWhileLoopCount = {
|
|
80
80
|
id: "whileLoopCount",
|
|
81
|
-
label: "Nombre d
|
|
81
|
+
label: "Nombre d'itérations d'une boucle while (Python)",
|
|
82
82
|
isSingleStep: true,
|
|
83
83
|
generator: (nb) => getDistinctQuestions(getPyWhileLoopCountQuestion, nb),
|
|
84
84
|
qcmTimer: 60,
|
package/lib/index.d.ts
CHANGED
|
@@ -74,6 +74,9 @@ declare const mathExercises: (Exercise<{
|
|
|
74
74
|
}, {}> | Exercise<{
|
|
75
75
|
a: import("./tree/nodes/nodeConstructor.js").NodeIdentifiers;
|
|
76
76
|
b: import("./tree/nodes/nodeConstructor.js").NodeIdentifiers;
|
|
77
|
+
}, {}> | Exercise<{
|
|
78
|
+
a: number;
|
|
79
|
+
b: number;
|
|
77
80
|
}, {}> | Exercise<{
|
|
78
81
|
integerFirst: boolean;
|
|
79
82
|
integer: number;
|
|
@@ -279,6 +282,9 @@ declare const mathExercises: (Exercise<{
|
|
|
279
282
|
sign: number;
|
|
280
283
|
}, {}> | Exercise<{
|
|
281
284
|
n: number;
|
|
285
|
+
}, {}> | Exercise<{
|
|
286
|
+
a: number;
|
|
287
|
+
isOpposite: boolean;
|
|
282
288
|
}, {}> | Exercise<{
|
|
283
289
|
a: number;
|
|
284
290
|
b: number;
|
|
@@ -2132,7 +2138,6 @@ declare const mathExercises: (Exercise<{
|
|
|
2132
2138
|
}, {}> | Exercise<{
|
|
2133
2139
|
initialValue: number;
|
|
2134
2140
|
step: number;
|
|
2135
|
-
iterations: number;
|
|
2136
2141
|
opIndex: number;
|
|
2137
2142
|
a: number;
|
|
2138
2143
|
x: number;
|
|
@@ -2158,6 +2163,15 @@ declare const mathExercises: (Exercise<{
|
|
|
2158
2163
|
}, {}> | Exercise<{
|
|
2159
2164
|
inputValue: number;
|
|
2160
2165
|
threshold: number;
|
|
2166
|
+
}, {}> | Exercise<{
|
|
2167
|
+
a: number;
|
|
2168
|
+
b: number;
|
|
2169
|
+
opName: string;
|
|
2170
|
+
condition: string;
|
|
2171
|
+
}, {}> | Exercise<{
|
|
2172
|
+
variableName: string;
|
|
2173
|
+
initialVariable: number;
|
|
2174
|
+
affines: import("./math/polynomials/affine.js").Affine[];
|
|
2161
2175
|
}, {}> | Exercise<{
|
|
2162
2176
|
p: number;
|
|
2163
2177
|
n: number;
|