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.
Files changed (75) hide show
  1. package/lib/exercises/math/calculLitteral/distributivity/simpleDistri.js +1 -1
  2. package/lib/exercises/math/calculLitteral/equation/equationSimpleSquare.js +3 -3
  3. package/lib/exercises/math/calculLitteral/systems/basicSystemResolution.js +4 -4
  4. package/lib/exercises/math/calculLitteral/systems/verifySystemSolution.d.ts.map +1 -1
  5. package/lib/exercises/math/calculLitteral/systems/verifySystemSolution.js +7 -9
  6. package/lib/exercises/math/conversion/aeraConversion.js +1 -1
  7. package/lib/exercises/math/conversion/capacityConversion.js +2 -2
  8. package/lib/exercises/math/derivation/tangent/derivativeTangentEquationReading.d.ts.map +1 -1
  9. package/lib/exercises/math/derivation/tangent/derivativeTangentEquationReading.js +17 -9
  10. package/lib/exercises/math/derivation/variations/thirdDegreeFunctionVariation.d.ts.map +1 -1
  11. package/lib/exercises/math/derivation/variations/thirdDegreeFunctionVariation.js +3 -0
  12. package/lib/exercises/math/functions/affines/interceptReading.js +1 -1
  13. package/lib/exercises/math/functions/affines/leadingCoefficient.d.ts.map +1 -1
  14. package/lib/exercises/math/functions/affines/leadingCoefficient.js +8 -2
  15. package/lib/exercises/math/functions/affines/leadingCoefficientCalculV2.js +1 -1
  16. package/lib/exercises/math/geometry/cartesian/cartesianEquationOfLine.js +1 -1
  17. package/lib/exercises/math/geometry/cartesian/cartesianFromTwoPoints.d.ts.map +1 -1
  18. package/lib/exercises/math/geometry/cartesian/cartesianFromTwoPoints.js +12 -8
  19. package/lib/exercises/math/geometry/cartesian/cartesianFromVectorAndPoint.js +3 -3
  20. package/lib/exercises/math/geometry/cartesian/directionVector.js +1 -1
  21. package/lib/exercises/math/geometry/cartesian/directionVectorEquation.js +1 -1
  22. package/lib/exercises/math/geometry/cartesian/drawAlineInGGB.d.ts.map +1 -1
  23. package/lib/exercises/math/geometry/cartesian/drawAlineInGGB.js +3 -3
  24. package/lib/exercises/math/geometry/lines/cartesianEquationToReduced.js +5 -5
  25. package/lib/exercises/math/geometry/lines/cartesianEquationsIntersection.js +2 -2
  26. package/lib/exercises/math/geometry/lines/directorVectorFromAnother.js +1 -1
  27. package/lib/exercises/math/geometry/lines/directorVectorFromReductEquation.d.ts.map +1 -1
  28. package/lib/exercises/math/geometry/lines/directorVectorFromReductEquation.js +11 -6
  29. package/lib/exercises/math/geometry/lines/drawLineFromCartesianEquation.js +5 -5
  30. package/lib/exercises/math/geometry/lines/drawLineFromPointAndVector.js +3 -3
  31. package/lib/exercises/math/geometry/lines/findParallelLineFromCartesianEquation.js +3 -3
  32. package/lib/exercises/math/geometry/lines/findParallelLineFromReductEquation.js +1 -1
  33. package/lib/exercises/math/geometry/lines/isPointOnCartesianLine.js +2 -2
  34. package/lib/exercises/math/geometry/lines/isPointOnLine.d.ts.map +1 -1
  35. package/lib/exercises/math/geometry/lines/isPointOnLine.js +2 -2
  36. package/lib/exercises/math/geometry/lines/reductEquationFindY.d.ts.map +1 -1
  37. package/lib/exercises/math/geometry/lines/reductEquationFindY.js +12 -3
  38. package/lib/exercises/math/geometry/lines/reductEquationFromTwoPoints.js +3 -3
  39. package/lib/exercises/math/geometry/parametric/extractPointFromParametricLine.js +1 -1
  40. package/lib/exercises/math/geometry/perimeters/circleCircumference.d.ts.map +1 -1
  41. package/lib/exercises/math/geometry/perimeters/circleCircumference.js +8 -9
  42. package/lib/exercises/math/geometry/vectors/alignementViaColinearity.d.ts.map +1 -1
  43. package/lib/exercises/math/geometry/vectors/alignementViaColinearity.js +9 -5
  44. package/lib/exercises/math/geometry/vectors/lineFromDirectorVector.js +4 -4
  45. package/lib/exercises/math/geometry/volumes/volumeOfPyramidWithTriangleBase.d.ts.map +1 -1
  46. package/lib/exercises/math/geometry/volumes/volumeOfPyramidWithTriangleBase.js +0 -2
  47. package/lib/exercises/math/probaStat/stats1var/quartiles.d.ts.map +1 -1
  48. package/lib/exercises/math/probaStat/stats1var/quartiles.js +6 -7
  49. package/lib/exercises/math/python/conditionIf.d.ts +1 -1
  50. package/lib/exercises/math/python/conditionIf.d.ts.map +1 -1
  51. package/lib/exercises/math/python/conditionIf.js +29 -16
  52. package/lib/exercises/math/python/forLoop.d.ts.map +1 -1
  53. package/lib/exercises/math/python/forLoop.js +30 -18
  54. package/lib/exercises/math/python/inOutCalcul.d.ts.map +1 -1
  55. package/lib/exercises/math/python/inOutCalcul.js +25 -12
  56. package/lib/exercises/math/python/pyForLoop1Exercise.d.ts +4 -7
  57. package/lib/exercises/math/python/pyForLoop1Exercise.d.ts.map +1 -1
  58. package/lib/exercises/math/python/pyForLoop1Exercise.js +77 -118
  59. package/lib/exercises/math/python/pyNestedForLoopExercise.d.ts +0 -3
  60. package/lib/exercises/math/python/pyNestedForLoopExercise.d.ts.map +1 -1
  61. package/lib/exercises/math/python/pyNestedForLoopExercise.js +50 -51
  62. package/lib/exercises/math/python/pyWhileLoop1Exercise.d.ts +1 -3
  63. package/lib/exercises/math/python/pyWhileLoop1Exercise.d.ts.map +1 -1
  64. package/lib/exercises/math/python/pyWhileLoop1Exercise.js +70 -74
  65. package/lib/exercises/math/python/pythonFunctionTrinom.d.ts.map +1 -1
  66. package/lib/exercises/math/python/pythonFunctionTrinom.js +26 -13
  67. package/lib/exercises/math/python/whileLoop.d.ts.map +1 -1
  68. package/lib/exercises/math/python/whileLoop.js +30 -18
  69. package/lib/exercises/math/sequences/arithmetic/arithmeticExplicitFormulaUsage.js +1 -1
  70. package/lib/exercises/math/sequences/geometric/geometricExplicitFormulaUsage.js +1 -1
  71. package/lib/index.d.ts +12 -17
  72. package/lib/index.d.ts.map +1 -1
  73. package/lib/math/geometry/vector.js +1 -1
  74. package/lib/math/systems/generalSystem.js +5 -5
  75. 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
- import { NumberNode } from "../../../tree/nodes/numbers/numberNode.js";
5
- import { MultiplyNode } from "../../../tree/nodes/operators/multiplyNode.js";
6
- import { coinFlip } from "../../../utils/alea/coinFlip.js";
7
- import { random } from "../../../utils/alea/random.js";
8
- const getPythonForLoop1ExerciseQuestion = () => {
9
- const exercise = generateRandomExercise();
10
- const correctAnswer = getCorrectAnswer(exercise.exoVariable);
11
- const question = {
12
- answer: correctAnswer + "",
13
- instruction: exercise.instruction,
14
- keys: [],
15
- answerFormat: "tex",
16
- identifiers: { exercise: exercise.exoVariable },
17
- };
18
- return question;
19
- };
20
- const generateRandomExercise = () => {
21
- const isType5 = coinFlip();
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 getPropositions = (n, { answer, exercise }) => {
25
- const propositions = [];
26
- addValidProp(propositions, answer);
27
- generatePropostion(exercise).forEach((value) => tryToAddWrongProp(propositions, value));
28
- while (propositions.length < n) {
29
- let correctAnswer = getCorrectAnswer(exercise);
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 generateType5Exercise = () => {
46
- const a = randint(-10, 11);
47
- const operands = ["+", "-"];
48
- const nbIterations = [1000, 100, 10];
49
- const nbIteration = random(nbIterations);
50
- let op = random(operands);
51
- const exoVariable = {
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 generateType6Exercise = () => {
67
- const a = randint(-4, 4, [0]);
68
- const b = randint(1, 4);
69
- const nbIteration = randint(3, 6);
70
- const exoVariable = {
71
- a,
72
- nbIteration,
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
- const instruction = `Qu'affiche le programme suivant, si l'utilisateur entre $${a}$ ?
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 getCorrectAnswer = (exercise) => {
105
- if (exercise.b !== undefined) {
106
- return getType6CorrectAnswer(exercise.a, exercise.b, exercise.nbIteration);
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
- else {
109
- return getType5CorrectAnswer(exercise.a, exercise.op, exercise.nbIteration);
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
- const getType5CorrectAnswer = (a, op, nbIteration) => {
113
- const multiplied = nbIteration * 0.5;
114
- switch (op) {
115
- case "+":
116
- return a + multiplied;
117
- case "-":
118
- return a - multiplied;
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 1;
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, { exercise }) => {
127
- return getCorrectAnswer(exercise) + "" === ans;
86
+ const isAnswerValid = (ans, { answer }) => {
87
+ return ans === answer;
128
88
  };
129
89
  export const pythonForLoop1Exercise = {
130
90
  id: "pyForLoop1Exercise",
131
- label: "Boucles for $1$",
132
- levels: ["2nde"],
91
+ label: "Boucle for (avec entrée utilisateur)",
133
92
  isSingleStep: true,
134
- sections: ["Python"],
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,8 +1,5 @@
1
1
  import { Exercise } from "../../../exercises/exercise.js";
2
2
  type Identifiers = {
3
- exercise: PyExoVariables;
4
- };
5
- type PyExoVariables = {
6
3
  op: string;
7
4
  n: number;
8
5
  p: number;
@@ -1 +1 @@
1
- {"version":3,"file":"pyNestedForLoopExercise.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/python/pyNestedForLoopExercise.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAST,MAAM,6BAA6B,CAAC;AAKrC,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,cAAc,CAAC;CAC1B,CAAC;AAOF,KAAK,cAAc,GAAG;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX,CAAC;AAqFF,eAAO,MAAM,uBAAuB,EAAE,QAAQ,CAAC,WAAW,CAazD,CAAC"}
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 operators = ["+", "-"];
6
- const getPyNestedForLoopExerciseQuestion = () => {
7
- const exercise = generateExercise();
8
- const correctAnswer = getCorrectAnswer(exercise.exoVariables);
9
- const question = {
10
- answer: correctAnswer + "",
11
- instruction: exercise.instruction,
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 getPropositions = (n, { answer, exercise }) => {
19
- const propositions = [];
20
- addValidProp(propositions, answer);
21
- generateProposition(exercise).forEach((value) => tryToAddWrongProp(propositions, value + ""));
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 generateExercise = () => {
44
- const op = random(operators);
45
- const n = randint(2, 11);
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 getCorrectAnswer = (exo) => {
66
- const nbIteration = exo.p * exo.n;
67
- return exo.op == "+" ? nbIteration : -nbIteration;
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,EAST,MAAM,6BAA6B,CAAC;AAMrC,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,cAAc,CAAC;CAC1B,CAAC;AAOF,KAAK,cAAc,GAAG;IACpB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AA8IF,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,WAAW,CAatD,CAAC"}
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 exoTypes = ["16", "17"];
6
- const operators = ["+", "*"];
7
- const getPyWhileLoop1ExerciseQuestion = () => {
8
- const exercise = generateRandomExercise();
9
- const correctAnswer = getCorrectAnswer(exercise.exoVariables);
10
- const question = {
11
- answer: correctAnswer + "",
12
- instruction: exercise.instruction,
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 generateInstruction = (exoType, a, n, op) => {
66
- switch (exoType) {
67
- case "16":
68
- return generateType16Instruction(a, n, op);
69
- case "17":
70
- return generateType17Instruction(a, n, op);
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 generateType16Instruction = (a, b, op) => {
75
- const instruction = `Qu'affichera le programme suivant ?
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 instruction;
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
- return instruction;
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,EAST,MAAM,6BAA6B,CAAC;AAYrC,KAAK,WAAW,GAAG;IACjB,CAAC,EAAE,MAAM,CAAC;IACV,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAoDF,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,WAAW,CAatD,CAAC"}
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 getPythonFunctionTrinomQuestion = () => {
8
- const trinom = TrinomConstructor.random();
9
- const x = randint(-5, 5);
10
- const image = trinom.calculate(x);
11
- const equation = trinom.toPython();
12
- const question = {
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: { x, trinom: [trinom.a, trinom.b, trinom.c], image },
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,EAST,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;AA8EF,eAAO,MAAM,SAAS,EAAE,QAAQ,CAAC,WAAW,CAY3C,CAAC"}
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"}