math-exercises 3.0.61 → 3.0.63
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/calculLitteral/distributivity/simpleDistri.js +1 -1
- package/lib/exercises/math/calculLitteral/equation/equationSimpleSquare.js +3 -3
- package/lib/exercises/math/calculLitteral/systems/basicSystemResolution.js +4 -4
- package/lib/exercises/math/calculLitteral/systems/verifySystemSolution.d.ts.map +1 -1
- package/lib/exercises/math/calculLitteral/systems/verifySystemSolution.js +7 -9
- package/lib/exercises/math/conversion/aeraConversion.js +1 -1
- package/lib/exercises/math/conversion/capacityConversion.js +2 -2
- package/lib/exercises/math/derivation/tangent/derivativeTangentEquationReading.d.ts.map +1 -1
- package/lib/exercises/math/derivation/tangent/derivativeTangentEquationReading.js +17 -9
- package/lib/exercises/math/derivation/variations/thirdDegreeFunctionVariation.d.ts.map +1 -1
- package/lib/exercises/math/derivation/variations/thirdDegreeFunctionVariation.js +3 -0
- package/lib/exercises/math/functions/affines/interceptReading.js +1 -1
- package/lib/exercises/math/functions/affines/leadingCoefficient.d.ts.map +1 -1
- package/lib/exercises/math/functions/affines/leadingCoefficient.js +8 -2
- package/lib/exercises/math/functions/affines/leadingCoefficientCalculV2.js +1 -1
- package/lib/exercises/math/geometry/cartesian/cartesianEquationOfLine.js +1 -1
- package/lib/exercises/math/geometry/cartesian/cartesianFromTwoPoints.d.ts.map +1 -1
- package/lib/exercises/math/geometry/cartesian/cartesianFromTwoPoints.js +12 -8
- package/lib/exercises/math/geometry/cartesian/cartesianFromVectorAndPoint.js +3 -3
- package/lib/exercises/math/geometry/cartesian/directionVector.js +1 -1
- package/lib/exercises/math/geometry/cartesian/directionVectorEquation.js +1 -1
- package/lib/exercises/math/geometry/cartesian/drawAlineInGGB.d.ts.map +1 -1
- package/lib/exercises/math/geometry/cartesian/drawAlineInGGB.js +3 -3
- package/lib/exercises/math/geometry/lines/cartesianEquationToReduced.js +5 -5
- package/lib/exercises/math/geometry/lines/cartesianEquationsIntersection.js +2 -2
- package/lib/exercises/math/geometry/lines/directorVectorFromAnother.js +1 -1
- package/lib/exercises/math/geometry/lines/directorVectorFromReductEquation.d.ts.map +1 -1
- package/lib/exercises/math/geometry/lines/directorVectorFromReductEquation.js +11 -6
- package/lib/exercises/math/geometry/lines/drawLineFromCartesianEquation.js +5 -5
- package/lib/exercises/math/geometry/lines/drawLineFromPointAndVector.js +3 -3
- package/lib/exercises/math/geometry/lines/findParallelLineFromCartesianEquation.js +3 -3
- package/lib/exercises/math/geometry/lines/findParallelLineFromReductEquation.js +1 -1
- package/lib/exercises/math/geometry/lines/isPointOnCartesianLine.js +2 -2
- package/lib/exercises/math/geometry/lines/isPointOnLine.d.ts.map +1 -1
- package/lib/exercises/math/geometry/lines/isPointOnLine.js +2 -2
- package/lib/exercises/math/geometry/lines/reductEquationFindY.d.ts.map +1 -1
- package/lib/exercises/math/geometry/lines/reductEquationFindY.js +12 -3
- package/lib/exercises/math/geometry/lines/reductEquationFromTwoPoints.js +3 -3
- package/lib/exercises/math/geometry/parametric/extractPointFromParametricLine.js +1 -1
- package/lib/exercises/math/geometry/perimeters/circleCircumference.d.ts.map +1 -1
- package/lib/exercises/math/geometry/perimeters/circleCircumference.js +8 -9
- package/lib/exercises/math/geometry/vectors/alignementViaColinearity.d.ts.map +1 -1
- package/lib/exercises/math/geometry/vectors/alignementViaColinearity.js +9 -5
- package/lib/exercises/math/geometry/vectors/lineFromDirectorVector.js +4 -4
- package/lib/exercises/math/geometry/volumes/volumeOfPyramidWithTriangleBase.d.ts.map +1 -1
- package/lib/exercises/math/geometry/volumes/volumeOfPyramidWithTriangleBase.js +0 -2
- package/lib/exercises/math/probaStat/stats1var/quartiles.d.ts.map +1 -1
- package/lib/exercises/math/probaStat/stats1var/quartiles.js +6 -7
- package/lib/exercises/math/python/conditionIf.d.ts +1 -1
- package/lib/exercises/math/python/conditionIf.d.ts.map +1 -1
- package/lib/exercises/math/python/conditionIf.js +29 -16
- package/lib/exercises/math/python/forLoop.d.ts.map +1 -1
- package/lib/exercises/math/python/forLoop.js +30 -18
- package/lib/exercises/math/python/inOutCalcul.d.ts.map +1 -1
- package/lib/exercises/math/python/inOutCalcul.js +25 -12
- package/lib/exercises/math/python/pyForLoop1Exercise.d.ts +4 -7
- package/lib/exercises/math/python/pyForLoop1Exercise.d.ts.map +1 -1
- package/lib/exercises/math/python/pyForLoop1Exercise.js +77 -118
- package/lib/exercises/math/python/pyNestedForLoopExercise.d.ts +0 -3
- package/lib/exercises/math/python/pyNestedForLoopExercise.d.ts.map +1 -1
- package/lib/exercises/math/python/pyNestedForLoopExercise.js +50 -51
- package/lib/exercises/math/python/pyWhileLoop1Exercise.d.ts +1 -3
- package/lib/exercises/math/python/pyWhileLoop1Exercise.d.ts.map +1 -1
- package/lib/exercises/math/python/pyWhileLoop1Exercise.js +70 -74
- package/lib/exercises/math/python/pythonFunctionTrinom.d.ts.map +1 -1
- package/lib/exercises/math/python/pythonFunctionTrinom.js +26 -13
- package/lib/exercises/math/python/whileLoop.d.ts.map +1 -1
- package/lib/exercises/math/python/whileLoop.js +30 -18
- package/lib/exercises/math/sequences/arithmetic/arithmeticExplicitFormulaUsage.js +1 -1
- package/lib/exercises/math/sequences/geometric/geometricExplicitFormulaUsage.js +1 -1
- package/lib/index.d.ts +12 -17
- package/lib/index.d.ts.map +1 -1
- package/lib/math/geometry/vector.js +1 -1
- package/lib/math/systems/generalSystem.js +5 -5
- package/package.json +1 -1
|
@@ -1,141 +1,100 @@
|
|
|
1
1
|
import { addValidProp, shuffleProps, tryToAddWrongProp, } from "../../../exercises/exercise.js";
|
|
2
2
|
import { getDistinctQuestions } from "../../../exercises/utils/getDistinctQuestions.js";
|
|
3
3
|
import { randint } from "../../../math/utils/random/randint.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return isType5 ? generateType5Exercise() : generateType6Exercise();
|
|
4
|
+
const operations = [
|
|
5
|
+
{ name: "+", func: (x, step) => x + step },
|
|
6
|
+
{ name: "-", func: (x, step) => x - step },
|
|
7
|
+
{ name: "*", func: (x, step) => x * step },
|
|
8
|
+
// { name: "//", func: (x: number, step: number) => Math.floor(x / step) }
|
|
9
|
+
];
|
|
10
|
+
const getInstruction = (identifiers) => {
|
|
11
|
+
const { initialValue, step, iterations, opIndex } = identifiers;
|
|
12
|
+
const op = operations[opIndex];
|
|
13
|
+
return `Qu'affichera le programme suivant, si l'utilisateur entre $${step}$ ?
|
|
14
|
+
\`\`\`
|
|
15
|
+
x = ${initialValue}
|
|
16
|
+
y = int(input("Entrez un nombre"))
|
|
17
|
+
for i in range(1, ${iterations + 1}):
|
|
18
|
+
x = x ${op.name} y
|
|
19
|
+
print(x)
|
|
20
|
+
\`\`\`
|
|
21
|
+
`;
|
|
23
22
|
};
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
let random = randint(correctAnswer - 15, correctAnswer + 16, [
|
|
31
|
-
correctAnswer,
|
|
32
|
-
]);
|
|
33
|
-
tryToAddWrongProp(propositions, random + "");
|
|
34
|
-
}
|
|
35
|
-
return shuffleProps(propositions, n);
|
|
36
|
-
};
|
|
37
|
-
const generatePropostion = (exercise) => {
|
|
38
|
-
if (exercise.b !== undefined) {
|
|
39
|
-
return generateType6Proposition(exercise.a, exercise.b, exercise.nbIteration);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
return generateType5Proposition(exercise.a, exercise.op, exercise.nbIteration);
|
|
23
|
+
const getAnswer = (identifiers) => {
|
|
24
|
+
const { initialValue, step, iterations, opIndex } = identifiers;
|
|
25
|
+
const op = operations[opIndex];
|
|
26
|
+
let value = initialValue;
|
|
27
|
+
for (let i = 0; i < iterations; i++) {
|
|
28
|
+
value = op.func(value, step);
|
|
43
29
|
}
|
|
30
|
+
const answer = value.toString();
|
|
31
|
+
return answer;
|
|
44
32
|
};
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
a,
|
|
53
|
-
nbIteration,
|
|
54
|
-
op,
|
|
55
|
-
};
|
|
56
|
-
const instruction = `Qu'affichera le programme suivant ?
|
|
57
|
-
\`\`\`
|
|
58
|
-
a=${a}
|
|
59
|
-
for i in range (1,${nbIteration + 1}):
|
|
60
|
-
a=a${op}0.5
|
|
61
|
-
print(a)
|
|
62
|
-
\`\`\`
|
|
63
|
-
`;
|
|
64
|
-
return { instruction, exoVariable };
|
|
33
|
+
const getForLoopQuestion = () => {
|
|
34
|
+
const initialValue = randint(-10, 10, [0, 1]);
|
|
35
|
+
const opIndex = randint(0, operations.length);
|
|
36
|
+
const step = randint(0, 10, [0, 1]);
|
|
37
|
+
const iterations = randint(1, 6, [1]);
|
|
38
|
+
const identifiers = { initialValue, step, iterations, opIndex };
|
|
39
|
+
return getQuestionFromIdentifiers(identifiers);
|
|
65
40
|
};
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
op: "*",
|
|
74
|
-
b,
|
|
41
|
+
const getQuestionFromIdentifiers = (identifiers) => {
|
|
42
|
+
const question = {
|
|
43
|
+
answer: getAnswer(identifiers),
|
|
44
|
+
instruction: getInstruction(identifiers),
|
|
45
|
+
keys: ["a", "equal"],
|
|
46
|
+
answerFormat: "tex",
|
|
47
|
+
identifiers,
|
|
75
48
|
};
|
|
76
|
-
|
|
77
|
-
\`\`\`
|
|
78
|
-
b=${b}
|
|
79
|
-
a=int(input("Entrez un nombre"))
|
|
80
|
-
for i in range(1,${nbIteration + 1}):
|
|
81
|
-
b=b*a
|
|
82
|
-
print(b)
|
|
83
|
-
\`\`\`
|
|
84
|
-
`;
|
|
85
|
-
return { instruction, exoVariable };
|
|
86
|
-
};
|
|
87
|
-
const generateType5Proposition = (a, op, nbIteration) => {
|
|
88
|
-
let firstPropostion = new NumberNode(getType5CorrectAnswer(a, op, nbIteration) + 0.5);
|
|
89
|
-
let secondProposition = new NumberNode(getType5CorrectAnswer(a, op, nbIteration) - 0.5);
|
|
90
|
-
return [firstPropostion.toTex(), secondProposition.toTex()];
|
|
91
|
-
};
|
|
92
|
-
const generateType6Proposition = (a, b, nbIteration) => {
|
|
93
|
-
const aNode = new NumberNode(a);
|
|
94
|
-
const bNode = new NumberNode(b);
|
|
95
|
-
const firstPropostion = new MultiplyNode(bNode, aNode);
|
|
96
|
-
const secondProposition = getType6CorrectAnswer(a, b, nbIteration + 1);
|
|
97
|
-
const thirdProposition = getType6CorrectAnswer(a, b, nbIteration - 1);
|
|
98
|
-
return [
|
|
99
|
-
firstPropostion.simplify().toTex(),
|
|
100
|
-
secondProposition + "",
|
|
101
|
-
thirdProposition + "",
|
|
102
|
-
];
|
|
49
|
+
return question;
|
|
103
50
|
};
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
51
|
+
const getPropositions = (n, { answer, initialValue, step, iterations, opIndex }) => {
|
|
52
|
+
const propositions = [];
|
|
53
|
+
const correctAnswer = answer;
|
|
54
|
+
addValidProp(propositions, correctAnswer);
|
|
55
|
+
const op = operations[opIndex];
|
|
56
|
+
// Une itération en moins
|
|
57
|
+
let valueOneLess = initialValue;
|
|
58
|
+
for (let i = 0; i < iterations - 1; i++) {
|
|
59
|
+
valueOneLess = op.func(valueOneLess, step);
|
|
107
60
|
}
|
|
108
|
-
|
|
109
|
-
|
|
61
|
+
const wrongAnswerOneLess = valueOneLess.toString();
|
|
62
|
+
tryToAddWrongProp(propositions, wrongAnswerOneLess);
|
|
63
|
+
// Une itération en plus
|
|
64
|
+
let valueOneMore = initialValue;
|
|
65
|
+
for (let i = 0; i < iterations + 1; i++) {
|
|
66
|
+
valueOneMore = op.func(valueOneMore, step);
|
|
110
67
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
68
|
+
const wrongAnswerOneMore = valueOneMore.toString();
|
|
69
|
+
tryToAddWrongProp(propositions, wrongAnswerOneMore);
|
|
70
|
+
// Erreur sur le négatif
|
|
71
|
+
const valueNegative = parseInt(answer) * -1;
|
|
72
|
+
const wrongAnswerNegative = valueNegative.toString();
|
|
73
|
+
tryToAddWrongProp(propositions, wrongAnswerNegative);
|
|
74
|
+
// Troisième proposition aléatoire
|
|
75
|
+
while (propositions.length < n) {
|
|
76
|
+
let randomValue = initialValue;
|
|
77
|
+
const randomIterations = randint(1, 10);
|
|
78
|
+
for (let i = 0; i < randomIterations; i++) {
|
|
79
|
+
randomValue = op.func(randomValue, step);
|
|
80
|
+
}
|
|
81
|
+
const randomWrongAnswer = randomValue.toString();
|
|
82
|
+
tryToAddWrongProp(propositions, randomWrongAnswer);
|
|
119
83
|
}
|
|
120
|
-
return
|
|
121
|
-
};
|
|
122
|
-
const getType6CorrectAnswer = (a, b, nbIteration) => {
|
|
123
|
-
const multiplier = Math.pow(a, nbIteration);
|
|
124
|
-
return multiplier * b;
|
|
84
|
+
return shuffleProps(propositions, n);
|
|
125
85
|
};
|
|
126
|
-
const isAnswerValid = (ans, {
|
|
127
|
-
return
|
|
86
|
+
const isAnswerValid = (ans, { answer }) => {
|
|
87
|
+
return ans === answer;
|
|
128
88
|
};
|
|
129
89
|
export const pythonForLoop1Exercise = {
|
|
130
90
|
id: "pyForLoop1Exercise",
|
|
131
|
-
label: "
|
|
132
|
-
levels: ["2nde"],
|
|
91
|
+
label: "Boucle for (avec entrée utilisateur)",
|
|
133
92
|
isSingleStep: true,
|
|
134
|
-
|
|
135
|
-
generator: (nb) => getDistinctQuestions(getPythonForLoop1ExerciseQuestion, nb),
|
|
93
|
+
generator: (nb) => getDistinctQuestions(getForLoopQuestion, nb),
|
|
136
94
|
qcmTimer: 60,
|
|
137
95
|
freeTimer: 60,
|
|
138
96
|
getPropositions,
|
|
139
97
|
isAnswerValid,
|
|
140
98
|
subject: "Mathématiques",
|
|
99
|
+
getQuestionFromIdentifiers,
|
|
141
100
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pyNestedForLoopExercise.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/python/pyNestedForLoopExercise.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,
|
|
1
|
+
{"version":3,"file":"pyNestedForLoopExercise.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/python/pyNestedForLoopExercise.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,6BAA6B,CAAC;AAMrC,KAAK,WAAW,GAAG;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CAGX,CAAC;AA+EF,eAAO,MAAM,uBAAuB,EAAE,QAAQ,CAAC,WAAW,CAazD,CAAC"}
|
|
@@ -1,55 +1,25 @@
|
|
|
1
1
|
import { addValidProp, shuffleProps, tryToAddWrongProp, } from "../../../exercises/exercise.js";
|
|
2
2
|
import { getDistinctQuestions } from "../../../exercises/utils/getDistinctQuestions.js";
|
|
3
|
+
import { numberVEA } from "../../../exercises/vea/numberVEA.js";
|
|
3
4
|
import { randint } from "../../../math/utils/random/randint.js";
|
|
4
5
|
import { random } from "../../../utils/alea/random.js";
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
keys: [],
|
|
13
|
-
answerFormat: "tex",
|
|
14
|
-
identifiers: { exercise: exercise.exoVariables },
|
|
6
|
+
const rebuildIdentifiers = (oldIds) => {
|
|
7
|
+
if (oldIds.op)
|
|
8
|
+
return oldIds;
|
|
9
|
+
return {
|
|
10
|
+
op: oldIds.exercise.op,
|
|
11
|
+
n: oldIds.exercise.n,
|
|
12
|
+
p: oldIds.exercise.p,
|
|
15
13
|
};
|
|
16
|
-
return question;
|
|
17
14
|
};
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
while (propositions.length < n) {
|
|
23
|
-
tryToAddWrongProp(propositions, randint(+answer - 10, +answer + 11, [+answer]) + "");
|
|
24
|
-
}
|
|
25
|
-
return shuffleProps(propositions, n);
|
|
26
|
-
};
|
|
27
|
-
const generateProposition = (exo) => {
|
|
28
|
-
const exoProposition = {
|
|
29
|
-
op: exo.op,
|
|
30
|
-
n: exo.n + 1,
|
|
31
|
-
p: exo.p + 1,
|
|
32
|
-
};
|
|
33
|
-
const firstProposition = getCorrectAnswer(exoProposition);
|
|
34
|
-
exoProposition.p = exo.p - 1;
|
|
35
|
-
exoProposition.n = exo.n - 1;
|
|
36
|
-
const secondProposition = getCorrectAnswer(exoProposition);
|
|
37
|
-
const thridProposition = exo.op === "+" ? exo.n : -exo.n;
|
|
38
|
-
return [firstProposition, secondProposition, thridProposition];
|
|
39
|
-
};
|
|
40
|
-
const isAnswerValid = (ans, { exercise }) => {
|
|
41
|
-
return getCorrectAnswer(exercise) + "" === ans;
|
|
15
|
+
const getAnswer = (identifiers) => {
|
|
16
|
+
const { n, p, op } = identifiers;
|
|
17
|
+
const nbIteration = p * n;
|
|
18
|
+
return (op == "+" ? nbIteration : -nbIteration).frenchify();
|
|
42
19
|
};
|
|
43
|
-
const
|
|
44
|
-
const op =
|
|
45
|
-
|
|
46
|
-
const p = randint(2, 11);
|
|
47
|
-
const exoVariables = {
|
|
48
|
-
op,
|
|
49
|
-
n,
|
|
50
|
-
p,
|
|
51
|
-
};
|
|
52
|
-
const instruction = `Qu'affichera le programme suivant ?
|
|
20
|
+
const getInstruction = (identifiers) => {
|
|
21
|
+
const { n, p, op } = identifiers;
|
|
22
|
+
return `Qu'affichera le programme suivant ?
|
|
53
23
|
\`\`\`
|
|
54
24
|
s=0
|
|
55
25
|
n=${n}
|
|
@@ -60,22 +30,51 @@ const generateExercise = () => {
|
|
|
60
30
|
print(s)
|
|
61
31
|
\`\`\`
|
|
62
32
|
`;
|
|
63
|
-
return { instruction, exoVariables };
|
|
64
33
|
};
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
|
|
34
|
+
const getQuestionFromIdentifiers = (identifiers) => {
|
|
35
|
+
const question = {
|
|
36
|
+
answer: getAnswer(identifiers),
|
|
37
|
+
instruction: getInstruction(identifiers),
|
|
38
|
+
keys: [],
|
|
39
|
+
answerFormat: "tex",
|
|
40
|
+
identifiers,
|
|
41
|
+
};
|
|
42
|
+
return question;
|
|
43
|
+
};
|
|
44
|
+
const getPyNestedForLoopExerciseQuestion = () => {
|
|
45
|
+
const op = random(["+", "-"]);
|
|
46
|
+
const n = randint(2, 11);
|
|
47
|
+
const p = randint(2, 11);
|
|
48
|
+
const identifiers = { n, op, p };
|
|
49
|
+
return getQuestionFromIdentifiers(identifiers);
|
|
50
|
+
};
|
|
51
|
+
const getPropositions = (nb, { answer, n, op, p }) => {
|
|
52
|
+
const propositions = [];
|
|
53
|
+
addValidProp(propositions, answer);
|
|
54
|
+
const firstProposition = getAnswer({ n: n + 1, p: p + 1, op });
|
|
55
|
+
const secondProposition = getAnswer({ n: n - 1, p: p + 1, op });
|
|
56
|
+
const thridProposition = op === "+" ? n : -n;
|
|
57
|
+
tryToAddWrongProp(propositions, firstProposition + "");
|
|
58
|
+
tryToAddWrongProp(propositions, secondProposition + "");
|
|
59
|
+
tryToAddWrongProp(propositions, thridProposition + "");
|
|
60
|
+
while (propositions.length < nb) {
|
|
61
|
+
tryToAddWrongProp(propositions, randint(+answer - 10, +answer + 11, [+answer]) + "");
|
|
62
|
+
}
|
|
63
|
+
return shuffleProps(propositions, nb);
|
|
64
|
+
};
|
|
65
|
+
const isAnswerValid = (ans, { answer }) => {
|
|
66
|
+
return numberVEA(ans, answer);
|
|
68
67
|
};
|
|
69
68
|
export const pyNestedForLoopExercise = {
|
|
70
69
|
id: "pyNestedForLoopExercise",
|
|
71
70
|
label: "Boucles for imbriquées",
|
|
72
|
-
levels: ["2nde"],
|
|
73
71
|
isSingleStep: true,
|
|
74
|
-
sections: ["Python"],
|
|
75
72
|
generator: (nb) => getDistinctQuestions(getPyNestedForLoopExerciseQuestion, nb),
|
|
76
73
|
qcmTimer: 60,
|
|
77
74
|
freeTimer: 60,
|
|
78
75
|
getPropositions,
|
|
79
76
|
isAnswerValid,
|
|
80
77
|
subject: "Mathématiques",
|
|
78
|
+
getQuestionFromIdentifiers,
|
|
79
|
+
rebuildIdentifiers,
|
|
81
80
|
};
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { Exercise } from "../../../exercises/exercise.js";
|
|
2
2
|
type Identifiers = {
|
|
3
|
-
exercise: PyExoVariables;
|
|
4
|
-
};
|
|
5
|
-
type PyExoVariables = {
|
|
6
3
|
a: number;
|
|
7
4
|
b: number;
|
|
8
5
|
op: string;
|
|
6
|
+
withInput: boolean;
|
|
9
7
|
};
|
|
10
8
|
export declare const pyWhileLoop1Exercise: Exercise<Identifiers>;
|
|
11
9
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pyWhileLoop1Exercise.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/python/pyWhileLoop1Exercise.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,
|
|
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,CAatD,CAAC"}
|
|
@@ -1,78 +1,34 @@
|
|
|
1
1
|
import { addValidProp, shuffleProps, tryToAddWrongProp, } from "../../../exercises/exercise.js";
|
|
2
2
|
import { getDistinctQuestions } from "../../../exercises/utils/getDistinctQuestions.js";
|
|
3
|
+
import { numberVEA } from "../../../exercises/vea/numberVEA.js";
|
|
3
4
|
import { randint } from "../../../math/utils/random/randint.js";
|
|
5
|
+
import { coinFlip } from "../../../utils/alea/coinFlip.js";
|
|
4
6
|
import { random } from "../../../utils/alea/random.js";
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
keys: [],
|
|
14
|
-
answerFormat: "tex",
|
|
15
|
-
identifiers: { exercise: exercise.exoVariables },
|
|
7
|
+
const rebuildIdentifiers = (oldIds) => {
|
|
8
|
+
if (oldIds.op)
|
|
9
|
+
return oldIds;
|
|
10
|
+
return {
|
|
11
|
+
a: oldIds.exercise.a,
|
|
12
|
+
b: oldIds.exercise.b,
|
|
13
|
+
op: oldIds.exercise.op,
|
|
14
|
+
withInput: coinFlip(),
|
|
16
15
|
};
|
|
17
|
-
return question;
|
|
18
|
-
};
|
|
19
|
-
const getPropositions = (n, { answer, exercise }) => {
|
|
20
|
-
const propositions = [];
|
|
21
|
-
addValidProp(propositions, answer);
|
|
22
|
-
generateProposition(answer, exercise).forEach((value) => tryToAddWrongProp(propositions, value + ""));
|
|
23
|
-
const correctAnswer = getCorrectAnswer(exercise);
|
|
24
|
-
while (propositions.length < n) {
|
|
25
|
-
tryToAddWrongProp(propositions, randint(correctAnswer - 11, correctAnswer + 11, [correctAnswer, 0]) + "");
|
|
26
|
-
}
|
|
27
|
-
return shuffleProps(propositions, n);
|
|
28
|
-
};
|
|
29
|
-
const isAnswerValid = (ans, { exercise }) => {
|
|
30
|
-
const correctAnswer = getCorrectAnswer(exercise);
|
|
31
|
-
return "" + correctAnswer === ans;
|
|
32
|
-
};
|
|
33
|
-
const generateProposition = (answer, exercise) => {
|
|
34
|
-
const firstProposition = exercise.op === "*" ? +answer * exercise.b : +answer + exercise.b;
|
|
35
|
-
const secondProposition = exercise.op === "*" ? +answer / exercise.b : +answer - exercise.b;
|
|
36
|
-
return [firstProposition, secondProposition];
|
|
37
|
-
};
|
|
38
|
-
const getCorrectAnswer = (exercise) => {
|
|
39
|
-
switch (exercise.op) {
|
|
40
|
-
case "*":
|
|
41
|
-
return Math.pow(exercise.b, Math.ceil(Math.log(exercise.a) / Math.log(exercise.b)));
|
|
42
|
-
case "+":
|
|
43
|
-
return 1 + exercise.b * Math.ceil(exercise.a / exercise.b);
|
|
44
|
-
}
|
|
45
|
-
return exercise.b;
|
|
46
|
-
};
|
|
47
|
-
const generateRandomExercise = () => {
|
|
48
|
-
const combination = {
|
|
49
|
-
times: [
|
|
50
|
-
{ minB: 2, maxB: 2, maxIter: 10 },
|
|
51
|
-
{ minB: 3, maxB: 5, maxIter: 5 },
|
|
52
|
-
],
|
|
53
|
-
plus: [{ minB: 2, maxB: 8, maxIter: 10 }],
|
|
54
|
-
};
|
|
55
|
-
const op = random(operators);
|
|
56
|
-
const randCombination = op === "*" ? random(combination.times) : combination.plus[0];
|
|
57
|
-
const b = randint(randCombination.minB, randCombination.maxB + 1);
|
|
58
|
-
const nbIter = randint(2, randCombination.maxIter + 1);
|
|
59
|
-
const aA = op === "+" ? Math.ceil(b * nbIter) : Math.pow(b, nbIter);
|
|
60
|
-
const a = randint(aA / b, aA);
|
|
61
|
-
const randomType = random(exoTypes);
|
|
62
|
-
const instruction = generateInstruction(randomType, a, b, op);
|
|
63
|
-
return { instruction, exoVariables: { a, b, op } };
|
|
64
16
|
};
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
17
|
+
const getAnswer = (identifiers) => {
|
|
18
|
+
const { a, b, withInput, op } = identifiers;
|
|
19
|
+
let n = 1;
|
|
20
|
+
while (n <= a) {
|
|
21
|
+
if (op === "+")
|
|
22
|
+
n = b + n;
|
|
23
|
+
else
|
|
24
|
+
n = b * n;
|
|
71
25
|
}
|
|
72
|
-
return
|
|
26
|
+
return n.frenchify();
|
|
73
27
|
};
|
|
74
|
-
const
|
|
75
|
-
const
|
|
28
|
+
const getInstruction = (identifiers) => {
|
|
29
|
+
const { a, b, op, withInput } = identifiers;
|
|
30
|
+
if (!withInput)
|
|
31
|
+
return `Qu'affichera le programme suivant ?
|
|
76
32
|
\`\`\`
|
|
77
33
|
a=${a}
|
|
78
34
|
n=1
|
|
@@ -81,10 +37,7 @@ const generateType16Instruction = (a, b, op) => {
|
|
|
81
37
|
print(n)
|
|
82
38
|
\`\`\`
|
|
83
39
|
`;
|
|
84
|
-
return
|
|
85
|
-
};
|
|
86
|
-
const generateType17Instruction = (a, b, op) => {
|
|
87
|
-
const instruction = `Qu'affichera le programme suivant, si l'utilisateur entre $${a}$ ?
|
|
40
|
+
return `Qu'affichera le programme suivant, si l'utilisateur entre $${a}$ ?
|
|
88
41
|
\`\`\`
|
|
89
42
|
a=input("Entrez un entier naturel non nul.")
|
|
90
43
|
a=int(a)
|
|
@@ -94,18 +47,61 @@ const generateType17Instruction = (a, b, op) => {
|
|
|
94
47
|
print(n)
|
|
95
48
|
\`\`\`
|
|
96
49
|
`;
|
|
97
|
-
|
|
50
|
+
};
|
|
51
|
+
const getQuestionFromIdentifiers = (identifiers) => {
|
|
52
|
+
const question = {
|
|
53
|
+
answer: getAnswer(identifiers),
|
|
54
|
+
instruction: getInstruction(identifiers),
|
|
55
|
+
keys: [],
|
|
56
|
+
answerFormat: "tex",
|
|
57
|
+
identifiers,
|
|
58
|
+
};
|
|
59
|
+
return question;
|
|
60
|
+
};
|
|
61
|
+
const getPyWhileLoop1ExerciseQuestion = () => {
|
|
62
|
+
const combination = {
|
|
63
|
+
times: [
|
|
64
|
+
{ minB: 2, maxB: 2, maxIter: 10 },
|
|
65
|
+
{ minB: 3, maxB: 5, maxIter: 5 },
|
|
66
|
+
],
|
|
67
|
+
plus: [{ minB: 2, maxB: 8, maxIter: 10 }],
|
|
68
|
+
};
|
|
69
|
+
const op = random(["+", "*"]);
|
|
70
|
+
const randCombination = op === "*" ? random(combination.times) : combination.plus[0];
|
|
71
|
+
const b = randint(randCombination.minB, randCombination.maxB + 1);
|
|
72
|
+
const nbIter = randint(2, randCombination.maxIter + 1);
|
|
73
|
+
const aA = op === "+" ? Math.ceil(b * nbIter) : Math.pow(b, nbIter);
|
|
74
|
+
const a = randint(aA / b, aA);
|
|
75
|
+
const withInput = coinFlip();
|
|
76
|
+
const identifiers = { a, b, op, withInput };
|
|
77
|
+
return getQuestionFromIdentifiers(identifiers);
|
|
78
|
+
};
|
|
79
|
+
const getPropositions = (n, { answer, a, b, withInput, op }) => {
|
|
80
|
+
const propositions = [];
|
|
81
|
+
addValidProp(propositions, answer);
|
|
82
|
+
const firstProposition = op === "*" ? +answer * b : +answer + b;
|
|
83
|
+
tryToAddWrongProp(propositions, firstProposition + "");
|
|
84
|
+
const secondProposition = op === "*" ? +answer / b : +answer - b;
|
|
85
|
+
tryToAddWrongProp(propositions, secondProposition + "");
|
|
86
|
+
const correctAnswer = Number(getAnswer({ a, b, withInput, op }));
|
|
87
|
+
while (propositions.length < n) {
|
|
88
|
+
tryToAddWrongProp(propositions, randint(correctAnswer - 11, correctAnswer + 11, [correctAnswer, 0]) + "");
|
|
89
|
+
}
|
|
90
|
+
return shuffleProps(propositions, n);
|
|
91
|
+
};
|
|
92
|
+
const isAnswerValid = (ans, { answer, ...identifiers }) => {
|
|
93
|
+
return numberVEA(ans, answer);
|
|
98
94
|
};
|
|
99
95
|
export const pyWhileLoop1Exercise = {
|
|
100
96
|
id: "pyWhileLoop1Exercise",
|
|
101
97
|
label: "Boucles while $1$",
|
|
102
|
-
levels: ["2nde"],
|
|
103
98
|
isSingleStep: true,
|
|
104
|
-
sections: ["Python"],
|
|
105
99
|
generator: (nb) => getDistinctQuestions(getPyWhileLoop1ExerciseQuestion, nb),
|
|
106
100
|
qcmTimer: 60,
|
|
107
101
|
freeTimer: 60,
|
|
108
102
|
getPropositions,
|
|
109
103
|
isAnswerValid,
|
|
110
104
|
subject: "Mathématiques",
|
|
105
|
+
getQuestionFromIdentifiers,
|
|
106
|
+
rebuildIdentifiers,
|
|
111
107
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pythonFunctionTrinom.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/python/pythonFunctionTrinom.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,
|
|
1
|
+
{"version":3,"file":"pythonFunctionTrinom.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/python/pythonFunctionTrinom.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAYT,MAAM,6BAA6B,CAAC;AAOrC,KAAK,WAAW,GAAG;IACjB,CAAC,EAAE,MAAM,CAAC;IACV,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAsEF,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,WAAW,CAYtD,CAAC"}
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { addValidProp, shuffleProps, tryToAddWrongProp, } from "../../../exercises/exercise.js";
|
|
2
2
|
import { getDistinctQuestions } from "../../../exercises/utils/getDistinctQuestions.js";
|
|
3
|
-
import { TrinomConstructor } from "../../../math/polynomials/trinom.js";
|
|
3
|
+
import { Trinom, TrinomConstructor } from "../../../math/polynomials/trinom.js";
|
|
4
4
|
import { randint } from "../../../math/utils/random/randint.js";
|
|
5
5
|
import { EqualNode } from "../../../tree/nodes/equations/equalNode.js";
|
|
6
6
|
import { VariableNode } from "../../../tree/nodes/variables/variableNode.js";
|
|
7
|
-
const
|
|
8
|
-
const trinom =
|
|
9
|
-
const
|
|
10
|
-
const image =
|
|
11
|
-
const equation =
|
|
12
|
-
|
|
13
|
-
answer: image.toString(),
|
|
14
|
-
instruction: `Qu'affichera le programme suivant ?
|
|
7
|
+
const getInstruction = (identifiers) => {
|
|
8
|
+
const { x, trinom } = identifiers;
|
|
9
|
+
const tri = new Trinom(trinom[0], trinom[1], trinom[2]);
|
|
10
|
+
const image = tri.calculate(x);
|
|
11
|
+
const equation = tri.toPython();
|
|
12
|
+
return `Qu'affichera le programme suivant ?
|
|
15
13
|
\`\`\`
|
|
16
14
|
def f(x):
|
|
17
15
|
y = ${equation}
|
|
@@ -19,10 +17,26 @@ def f(x):
|
|
|
19
17
|
y = f(${x})
|
|
20
18
|
print(y)
|
|
21
19
|
\`\`\`
|
|
22
|
-
|
|
20
|
+
`;
|
|
21
|
+
};
|
|
22
|
+
const getAnswer = (identifiers) => {
|
|
23
|
+
const { image } = identifiers;
|
|
24
|
+
return image.frenchify();
|
|
25
|
+
};
|
|
26
|
+
const getPythonFunctionTrinomQuestion = () => {
|
|
27
|
+
const trinom = TrinomConstructor.random();
|
|
28
|
+
const x = randint(-5, 5);
|
|
29
|
+
const image = trinom.calculate(x);
|
|
30
|
+
const identifiers = { x, trinom: [trinom.a, trinom.b, trinom.c], image };
|
|
31
|
+
return getQuestionFromIdentifiers(identifiers);
|
|
32
|
+
};
|
|
33
|
+
const getQuestionFromIdentifiers = (identifiers) => {
|
|
34
|
+
const question = {
|
|
35
|
+
answer: getAnswer(identifiers),
|
|
36
|
+
instruction: getInstruction(identifiers),
|
|
23
37
|
keys: ["f", "x", "y", "equal"],
|
|
24
38
|
answerFormat: "tex",
|
|
25
|
-
identifiers
|
|
39
|
+
identifiers,
|
|
26
40
|
};
|
|
27
41
|
return question;
|
|
28
42
|
};
|
|
@@ -48,13 +62,12 @@ const isAnswerValid = (ans, { answer }) => {
|
|
|
48
62
|
export const pythonFunctionTrinom = {
|
|
49
63
|
id: "pythonFunctionTrinom",
|
|
50
64
|
label: "Valeur de retour d'une fonction",
|
|
51
|
-
levels: ["2nde"],
|
|
52
65
|
isSingleStep: true,
|
|
53
|
-
sections: ["Python"],
|
|
54
66
|
generator: (nb) => getDistinctQuestions(getPythonFunctionTrinomQuestion, nb),
|
|
55
67
|
qcmTimer: 60,
|
|
56
68
|
freeTimer: 60,
|
|
57
69
|
getPropositions,
|
|
58
70
|
isAnswerValid,
|
|
59
71
|
subject: "Mathématiques",
|
|
72
|
+
getQuestionFromIdentifiers,
|
|
60
73
|
};
|
|
@@ -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,EAYT,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;IAChB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX,CAAC;AA6FF,eAAO,MAAM,SAAS,EAAE,QAAQ,CAAC,WAAW,CAW3C,CAAC"}
|