math-exercises 3.0.123 → 3.0.125

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/calcul/arithmetics/primeNumbers.d.ts +1 -1
  2. package/lib/exercises/math/calcul/arithmetics/primeNumbers.d.ts.map +1 -1
  3. package/lib/exercises/math/calcul/arithmetics/primeNumbers.js +20 -14
  4. package/lib/exercises/math/calcul/fractions/fractionsMix.js +1 -1
  5. package/lib/exercises/math/conversion/volumeConversion.d.ts.map +1 -1
  6. package/lib/exercises/math/conversion/volumeConversion.js +7 -1
  7. package/lib/exercises/math/derivation/derivative/exp/expDerivativeFour.d.ts.map +1 -1
  8. package/lib/exercises/math/derivation/derivative/exp/expDerivativeFour.js +9 -3
  9. package/lib/exercises/math/functions/affines/affineFromExercise.d.ts +1 -1
  10. package/lib/exercises/math/functions/affines/affineFromExercise.d.ts.map +1 -1
  11. package/lib/exercises/math/functions/affines/affineFromExercise.js +123 -48
  12. package/lib/exercises/math/functions/affines/drawAffineFromLitExp.js +5 -5
  13. package/lib/exercises/math/functions/affines/recognizeAffineGraph.d.ts +2 -1
  14. package/lib/exercises/math/functions/affines/recognizeAffineGraph.d.ts.map +1 -1
  15. package/lib/exercises/math/functions/affines/recognizeAffineGraph.js +41 -24
  16. package/lib/exercises/math/functions/basics/findZeroesProductQuotient.d.ts.map +1 -1
  17. package/lib/exercises/math/functions/basics/findZeroesProductQuotient.js +29 -2
  18. package/lib/exercises/math/functions/basics/inverseImageFunctionGeogebra.d.ts.map +1 -1
  19. package/lib/exercises/math/functions/basics/inverseImageFunctionGeogebra.js +72 -61
  20. package/lib/exercises/math/functions/logarithm/powerEquation.d.ts.map +1 -1
  21. package/lib/exercises/math/functions/logarithm/powerEquation.js +0 -1
  22. package/lib/exercises/math/functions/trinoms/roots/rootsFromDevForm.d.ts.map +1 -1
  23. package/lib/exercises/math/functions/trinoms/roots/rootsFromDevForm.js +41 -16
  24. package/lib/exercises/math/functions/trinoms/roots/rootsReading.d.ts.map +1 -1
  25. package/lib/exercises/math/functions/trinoms/roots/rootsReading.js +3 -2
  26. package/lib/exercises/math/functions/trinoms/sign/trinomSignFromFacto.d.ts +1 -0
  27. package/lib/exercises/math/functions/trinoms/sign/trinomSignFromFacto.d.ts.map +1 -1
  28. package/lib/exercises/math/functions/trinoms/sign/trinomSignFromFacto.js +21 -13
  29. package/lib/exercises/math/geometry/perimeters/circleCircumference.d.ts.map +1 -1
  30. package/lib/exercises/math/geometry/perimeters/circleCircumference.js +15 -7
  31. package/lib/exercises/math/geometry/shapes/basicShapesNaming.d.ts.map +1 -1
  32. package/lib/exercises/math/geometry/shapes/basicShapesNaming.js +5 -3
  33. package/lib/exercises/math/geometry/vectors/vectorLinearCombination.d.ts.map +1 -1
  34. package/lib/exercises/math/geometry/vectors/vectorLinearCombination.js +0 -1
  35. package/lib/exercises/math/percent/evolutions/evolutionToCM.js +2 -2
  36. package/lib/exercises/math/percent/findProportion.d.ts +6 -1
  37. package/lib/exercises/math/percent/findProportion.d.ts.map +1 -1
  38. package/lib/exercises/math/percent/findProportion.js +162 -45
  39. package/lib/exercises/math/powers/calculateNegativePower.d.ts +5 -1
  40. package/lib/exercises/math/powers/calculateNegativePower.d.ts.map +1 -1
  41. package/lib/exercises/math/powers/calculateNegativePower.js +93 -29
  42. package/lib/exercises/math/probaStat/probaFromTableNoContext.d.ts.map +1 -1
  43. package/lib/exercises/math/probaStat/probaFromTableNoContext.js +10 -2
  44. package/lib/exercises/math/probaStat/probaFromTableWithContext.d.ts.map +1 -1
  45. package/lib/exercises/math/probaStat/probaFromTableWithContext.js +2 -1
  46. package/lib/exercises/math/probaStat/stats1var/quartilesList.d.ts +4 -1
  47. package/lib/exercises/math/probaStat/stats1var/quartilesList.d.ts.map +1 -1
  48. package/lib/exercises/math/probaStat/stats1var/quartilesList.js +46 -27
  49. package/lib/exercises/math/sequences/geometric/geometricFindExplicitFormula.d.ts.map +1 -1
  50. package/lib/exercises/math/sequences/geometric/geometricFindExplicitFormula.js +14 -2
  51. package/lib/exercises/math/sequences/geometric/geometricReasonUsage.d.ts +1 -0
  52. package/lib/exercises/math/sequences/geometric/geometricReasonUsage.d.ts.map +1 -1
  53. package/lib/exercises/math/sequences/geometric/geometricReasonUsage.js +43 -19
  54. package/lib/exercises/math/sequences/sequenceEvaluation.d.ts.map +1 -1
  55. package/lib/exercises/math/sequences/sequenceEvaluation.js +18 -1
  56. package/lib/exercises/pc/chemicalReactions/chemicalEquations.d.ts.map +1 -1
  57. package/lib/exercises/pc/chemicalReactions/chemicalEquations.js +17 -2
  58. package/lib/exercises/pc/mole/molarMass.d.ts.map +1 -1
  59. package/lib/exercises/pc/mole/molarMass.js +7 -1
  60. package/lib/exercises/pc/motion/averageSpeed.d.ts +9 -4
  61. package/lib/exercises/pc/motion/averageSpeed.d.ts.map +1 -1
  62. package/lib/exercises/pc/motion/averageSpeed.js +132 -61
  63. package/lib/exercises/pc/motion/averageSpeedCalculation.d.ts.map +1 -1
  64. package/lib/exercises/pc/motion/averageSpeedCalculation.js +10 -4
  65. package/lib/exercises/pc/recognizeRefractionOrReflectionAngles.d.ts +2 -2
  66. package/lib/exercises/pc/recognizeRefractionOrReflectionAngles.js +15 -15
  67. package/lib/exercises/utils/geogebra/toolBarConstructor.d.ts +1 -0
  68. package/lib/exercises/utils/geogebra/toolBarConstructor.d.ts.map +1 -1
  69. package/lib/exercises/utils/geogebra/toolBarConstructor.js +3 -1
  70. package/lib/index.d.ts +49 -13
  71. package/lib/index.d.ts.map +1 -1
  72. package/lib/pc/units/timeUnits.d.ts +5 -3
  73. package/lib/pc/units/timeUnits.d.ts.map +1 -1
  74. package/lib/pc/units/timeUnits.js +25 -19
  75. package/package.json +1 -1
@@ -2,11 +2,13 @@ import { addValidProp, propWhile, tryToAddWrongProp, } from "../../../../exercis
2
2
  import { getDistinctQuestions } from "../../../../exercises/utils/getDistinctQuestions.js";
3
3
  import { randint } from "../../../../math/utils/random/randint.js";
4
4
  import { NumberNode } from "../../../../tree/nodes/numbers/numberNode.js";
5
- import { EqualNode } from "../../../../tree/nodes/equations/equalNode.js";
5
+ import { EqualNode, isEqualNode, } from "../../../../tree/nodes/equations/equalNode.js";
6
6
  import { MultiplyNode } from "../../../../tree/nodes/operators/multiplyNode.js";
7
7
  import { PowerNode } from "../../../../tree/nodes/operators/powerNode.js";
8
8
  import { VariableNode } from "../../../../tree/nodes/variables/variableNode.js";
9
9
  import { shuffle } from "../../../../utils/alea/shuffle.js";
10
+ import { parseLatex } from "../../../../tree/parsers/latexParser.js";
11
+ import { substract } from "../../../../tree/nodes/operators/substractNode.js";
10
12
  const getInstruction = (identifiers) => {
11
13
  const { firstValue, reason } = identifiers;
12
14
  const firstRank = 0;
@@ -81,7 +83,17 @@ const isAnswerValid = (ans, { reason, firstValue }) => {
81
83
  allowRawRightChildAsSolution: true,
82
84
  });
83
85
  const texs = equal.toAllValidTexs();
84
- return texs.includes(ans);
86
+ return (texs.includes(ans) ||
87
+ (() => {
88
+ let nodeAns = parseLatex(ans);
89
+ if (isEqualNode(nodeAns)) {
90
+ nodeAns = nodeAns.rightChild;
91
+ }
92
+ const differenceNode = substract(nodeAns, formula);
93
+ return (differenceNode.evaluate({ n: 0 }) === 0 &&
94
+ differenceNode.evaluate({ n: 1 }) === 0 &&
95
+ differenceNode.evaluate({ n: 5 }) === 0);
96
+ })());
85
97
  };
86
98
  export const geometricFindExplicitFormula = {
87
99
  id: "geometricFindExplicitFormula",
@@ -2,6 +2,7 @@ import { Exercise } from "../../../../exercises/exercise.js";
2
2
  type Identifiers = {
3
3
  reason: number;
4
4
  startRank: number;
5
+ askedRank: number;
5
6
  startValue: number;
6
7
  };
7
8
  export declare const geometricReasonUsage: Exercise<Identifiers>;
@@ -1 +1 @@
1
- {"version":3,"file":"geometricReasonUsage.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/sequences/geometric/geometricReasonUsage.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,6BAA6B,CAAC;AAKrC,KAAK,WAAW,GAAG;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAqEF,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,WAAW,CAYtD,CAAC"}
1
+ {"version":3,"file":"geometricReasonUsage.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/sequences/geometric/geometricReasonUsage.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAcT,MAAM,6BAA6B,CAAC;AAUrC,KAAK,WAAW,GAAG;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAwGF,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,WAAW,CAYtD,CAAC"}
@@ -1,20 +1,26 @@
1
- import { addValidProp, propWhile, tryToAddWrongProp, } from "../../../../exercises/exercise.js";
1
+ import { addValidProp, propWhile, 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 { shuffle } from "../../../../utils/alea/shuffle.js";
4
+ import { add } from "../../../../tree/nodes/operators/addNode.js";
5
+ import { multiply } from "../../../../tree/nodes/operators/multiplyNode.js";
6
+ import { power } from "../../../../tree/nodes/operators/powerNode.js";
7
+ import { substract } from "../../../../tree/nodes/operators/substractNode.js";
8
+ import { parseAlgebraic } from "../../../../tree/parsers/latexParser.js";
9
+ import { probaLawFlip } from "../../../../utils/alea/probaLawFlip.js";
5
10
  const getInstruction = (identifiers) => {
6
- const { reason, startRank, startValue } = identifiers;
7
- const askedRank = startRank + 1;
11
+ const { reason, startRank, startValue, askedRank } = identifiers;
8
12
  return `$(u_n)$ est une suite géométrique de raison $q = ${reason}$ et on sait que $u_{${startRank}} = ${startValue}$. Calculer : $u_{${askedRank}}$`;
9
13
  };
10
14
  const getAnswer = (identifiers) => {
11
- const { reason, startValue } = identifiers;
12
- const answer = (startValue * reason).toString();
15
+ const answer = getAnswerNode(identifiers).evaluate().frenchify();
13
16
  return answer;
14
17
  };
18
+ const getAnswerNode = (identifiers) => {
19
+ const { reason, startValue, startRank, askedRank } = identifiers;
20
+ return multiply(startValue, power(reason, substract(askedRank, startRank)));
21
+ };
15
22
  const getStartStatement = (identifiers) => {
16
- const { startRank } = identifiers;
17
- const askedRank = startRank + 1;
23
+ const { askedRank } = identifiers;
18
24
  return `u_{${askedRank}}`;
19
25
  };
20
26
  const getQuestionFromIdentifiers = (identifiers) => {
@@ -31,26 +37,44 @@ const getQuestionFromIdentifiers = (identifiers) => {
31
37
  const getGeometricReasonUsage = () => {
32
38
  const reason = randint(2, 10);
33
39
  const startRank = randint(0, 20);
40
+ const askedRank = startRank +
41
+ probaLawFlip([
42
+ [1, 0.5],
43
+ [2, 0.3],
44
+ [3, 0.2],
45
+ ]);
34
46
  const startValue = randint(1, 10);
35
- const identifiers = { startValue, reason, startRank };
47
+ const identifiers = { startValue, reason, startRank, askedRank };
36
48
  return getQuestionFromIdentifiers(identifiers);
37
49
  };
38
- const getPropositions = (n, { answer, startValue, reason }) => {
50
+ const getPropositions = (n, { answer, startValue, reason, askedRank, startRank }) => {
39
51
  const propositions = [];
40
52
  addValidProp(propositions, answer);
41
- if (startValue + reason !== 4)
42
- tryToAddWrongProp(propositions, (startValue + reason).toString());
53
+ //next term
54
+ tryToAddWrongProp(propositions, getAnswerNode({
55
+ startValue,
56
+ startRank,
57
+ reason,
58
+ askedRank: startRank + 1,
59
+ })
60
+ .evaluate()
61
+ .frenchify());
62
+ //arithmetic
63
+ tryToAddWrongProp(propositions, add(startValue, reason).evaluate().frenchify());
64
+ tryToAddWrongProp(propositions, add(startValue, multiply(reason, substract(askedRank, startRank)))
65
+ .evaluate()
66
+ .frenchify());
67
+ //savoir ses tables
43
68
  propWhile(propositions, n, () => {
44
69
  tryToAddWrongProp(propositions, startValue * (reason + randint(-reason + 1, 6, [0])) + "");
45
70
  });
46
- return shuffle(propositions);
71
+ return shuffleProps(propositions, n);
47
72
  };
48
- const isAnswerValid = (ans, { answer, startRank }) => {
49
- return [
50
- answer,
51
- `u_{${startRank}}=${answer}`,
52
- `u_${startRank}=${answer}`,
53
- ].includes(ans);
73
+ const isAnswerValid = (ans, { answer, ...identifiers }) => {
74
+ const { askedRank } = identifiers;
75
+ return ([answer, `u_{${askedRank}}=${answer}`, `u_${askedRank}=${answer}`].includes(ans) ||
76
+ //tant pis pour les tables
77
+ parseAlgebraic(ans).evaluate() === getAnswerNode(identifiers).evaluate());
54
78
  };
55
79
  export const geometricReasonUsage = {
56
80
  id: "geometricReasonUsage",
@@ -1 +1 @@
1
- {"version":3,"file":"sequenceEvaluation.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/sequences/sequenceEvaluation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,6BAA6B,CAAC;AAUrC,KAAK,WAAW,GAAG;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AA+MF,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,WAAW,CAYpD,CAAC"}
1
+ {"version":3,"file":"sequenceEvaluation.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/sequences/sequenceEvaluation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,6BAA6B,CAAC;AAYrC,KAAK,WAAW,GAAG;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAkOF,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,WAAW,CAYpD,CAAC"}
@@ -5,7 +5,9 @@ import { randint } from "../../../math/utils/random/randint.js";
5
5
  import { NumberNode } from "../../../tree/nodes/numbers/numberNode.js";
6
6
  import { AddNode } from "../../../tree/nodes/operators/addNode.js";
7
7
  import { MultiplyNode } from "../../../tree/nodes/operators/multiplyNode.js";
8
+ import { substract } from "../../../tree/nodes/operators/substractNode.js";
8
9
  import { VariableNode } from "../../../tree/nodes/variables/variableNode.js";
10
+ import { parseAlgebraic } from "../../../tree/parsers/latexParser.js";
9
11
  const getInstruction = (identifiers) => {
10
12
  const { termeid, affine, termeAdd, termeMult } = identifiers;
11
13
  const aff = new Affine(affine[0], affine[1], "n");
@@ -149,7 +151,22 @@ const isAnswerValid = (ans, { affine, termeid, termeAdd, termeMult }) => {
149
151
  });
150
152
  }
151
153
  const latexs = validanswer.toAllValidTexs();
152
- return latexs.includes(ans);
154
+ return (latexs.includes(ans) ||
155
+ (() => {
156
+ //allow "5 \\times n - 10"
157
+ const ansWithoutTimes = ans.replaceAll("\\times", "").replaceAll(" ", "");
158
+ const [nodeAns, nodeAnsWithoutTimes] = [ans, ansWithoutTimes].map((tex) => parseAlgebraic(tex));
159
+ const differenceNode = substract(nodeAns, nodeAnsWithoutTimes);
160
+ const isSameNode = differenceNode.evaluate({ n: 0 }) === 0 &&
161
+ differenceNode.evaluate({ n: 1 }) === 0 &&
162
+ differenceNode.evaluate({ n: 5 }) === 0;
163
+ if (!isSameNode) {
164
+ return false;
165
+ }
166
+ else {
167
+ return latexs.includes(ansWithoutTimes);
168
+ }
169
+ })());
153
170
  };
154
171
  export const sequenceEvaluation = {
155
172
  id: "sequenceEvaluation",
@@ -1 +1 @@
1
- {"version":3,"file":"chemicalEquations.d.ts","sourceRoot":"","sources":["../../../../src/exercises/pc/chemicalReactions/chemicalEquations.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAGL,eAAe,EAChB,MAAM,mDAAmD,CAAC;AAG3D,KAAK,WAAW,GAAG;IACjB,aAAa,EAAE,eAAe,EAAE,CAAC;CAClC,CAAC;AAwDF,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,WAAW,CAanD,CAAC"}
1
+ {"version":3,"file":"chemicalEquations.d.ts","sourceRoot":"","sources":["../../../../src/exercises/pc/chemicalReactions/chemicalEquations.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAGL,eAAe,EAChB,MAAM,mDAAmD,CAAC;AAI3D,KAAK,WAAW,GAAG;IACjB,aAAa,EAAE,eAAe,EAAE,CAAC;CAClC,CAAC;AAuEF,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,WAAW,CAanD,CAAC"}
@@ -17,7 +17,20 @@ const getAnswer = (identifiers) => {
17
17
  };
18
18
  const getKeys = (identifiers) => {
19
19
  const reaction = new Reaction(identifiers.reactionArray);
20
- return [...reaction.getKeyIds(), "rightarrow"];
20
+ return [
21
+ "rightarrow",
22
+ ...reaction.getSpeciesFormula().map((formula) => {
23
+ return {
24
+ id: "custom",
25
+ label: formula,
26
+ labelType: "tex",
27
+ mathfieldInstructions: {
28
+ method: "write",
29
+ content: formula,
30
+ },
31
+ };
32
+ }),
33
+ ];
21
34
  };
22
35
  const getQuestionFromIdentifiers = (identifiers) => {
23
36
  const question = {
@@ -44,7 +57,9 @@ const getPropositions = (n, { answer, reactionArray }) => {
44
57
  return shuffle(propositions);
45
58
  };
46
59
  const isAnswerValid = (ans, { answer }) => {
47
- return ans === answer;
60
+ const ansNoSpace = ans.replaceAll(" ", "");
61
+ const answerNoSpace = answer.replaceAll(" ", "");
62
+ return ansNoSpace === answerNoSpace;
48
63
  };
49
64
  export const chemicalEquations = {
50
65
  id: "chemicalEquations",
@@ -1 +1 @@
1
- {"version":3,"file":"molarMass.d.ts","sourceRoot":"","sources":["../../../../src/exercises/pc/mole/molarMass.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,6BAA6B,CAAC;AAQrC,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAwDF,eAAO,MAAM,SAAS,EAAE,QAAQ,CAAC,WAAW,CAY3C,CAAC"}
1
+ {"version":3,"file":"molarMass.d.ts","sourceRoot":"","sources":["../../../../src/exercises/pc/mole/molarMass.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,6BAA6B,CAAC;AAUrC,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAgEF,eAAO,MAAM,SAAS,EAAE,QAAQ,CAAC,WAAW,CAY3C,CAAC"}
@@ -3,6 +3,8 @@ import { getDistinctQuestions } from "../../../exercises/utils/getDistinctQuesti
3
3
  import { randfloat } from "../../../math/utils/random/randfloat.js";
4
4
  import { round, roundSignificant } from "../../../math/utils/round.js";
5
5
  import { molecules } from "../../../pc/constants/molecularChemistry/molecule.js";
6
+ import { substract } from "../../../tree/nodes/operators/substractNode.js";
7
+ import { parseAlgebraic } from "../../../tree/parsers/latexParser.js";
6
8
  import { random } from "../../../utils/alea/random.js";
7
9
  import { requiresApostropheBefore } from "../../../utils/strings/requiresApostropheBefore.js";
8
10
  const getInstruction = (identifiers) => {
@@ -41,7 +43,11 @@ const getPropositions = (n, { answer }) => {
41
43
  return shuffleProps(propositions, n);
42
44
  };
43
45
  const isAnswerValid = (ans, { answer }) => {
44
- return ans === answer;
46
+ return (ans === answer ||
47
+ (() => {
48
+ const [nodeAns, nodeAnswer] = [ans, answer].map((tex) => parseAlgebraic(tex));
49
+ return substract(nodeAns, nodeAnswer).evaluate() === 0;
50
+ })());
45
51
  };
46
52
  export const molarMass = {
47
53
  id: "molarMass",
@@ -1,12 +1,17 @@
1
1
  import { Exercise } from "../../../exercises/exercise.js";
2
+ type Msr = {
3
+ value: number;
4
+ unitIndex: number;
5
+ };
2
6
  type Identifiers = {
3
7
  distance: Msr;
4
8
  time: Msr;
9
+ opts: Options;
5
10
  };
6
- type Msr = {
7
- value: number;
8
- unitIndex: number;
11
+ type Options = {
12
+ acceptedInputType: string;
13
+ unitTex: string;
9
14
  };
10
- export declare const averageSpeed: Exercise<Identifiers>;
15
+ export declare const averageSpeed: Exercise<Identifiers, Options>;
11
16
  export {};
12
17
  //# sourceMappingURL=averageSpeed.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"averageSpeed.d.ts","sourceRoot":"","sources":["../../../../src/exercises/pc/motion/averageSpeed.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAeT,MAAM,6BAA6B,CAAC;AAUrC,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,GAAG,CAAC;IACd,IAAI,EAAE,GAAG,CAAC;CACX,CAAC;AAEF,KAAK,GAAG,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;AAuKhD,eAAO,MAAM,YAAY,EAAE,QAAQ,CAAC,WAAW,CAY9C,CAAC"}
1
+ {"version":3,"file":"averageSpeed.d.ts","sourceRoot":"","sources":["../../../../src/exercises/pc/motion/averageSpeed.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAmBT,MAAM,6BAA6B,CAAC;AAerC,KAAK,GAAG,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhD,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,GAAG,CAAC;IACd,IAAI,EAAE,GAAG,CAAC;IACV,IAAI,EAAE,OAAO,CAAC;CACf,CAAC;AA0NF,KAAK,OAAO,GAAG;IACb,iBAAiB,EAAE,MAAM,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAsBF,eAAO,MAAM,YAAY,EAAE,QAAQ,CAAC,WAAW,EAAE,OAAO,CAcvD,CAAC"}
@@ -1,4 +1,4 @@
1
- import { addValidProp, propWhile, shuffleProps, tryToAddWrongProp, } from "../../../exercises/exercise.js";
1
+ import { GeneratorOptionTarget, GeneratorOptionType, addValidProp, propWhile, shuffleProps, tryToAddWrongProp, } from "../../../exercises/exercise.js";
2
2
  import { getDistinctQuestions } from "../../../exercises/utils/getDistinctQuestions.js";
3
3
  import { randfloat } from "../../../math/utils/random/randfloat.js";
4
4
  import { randint } from "../../../math/utils/random/randint.js";
@@ -6,9 +6,25 @@ import { Measure } from "../../../pc/measure/measure.js";
6
6
  import { DistanceUnit } from "../../../pc/units/distanceUnits.js";
7
7
  import { TimeUnit } from "../../../pc/units/timeUnits.js";
8
8
  import { FractionNode } from "../../../tree/nodes/operators/fractionNode.js";
9
+ import { substract } from "../../../tree/nodes/operators/substractNode.js";
9
10
  import { VariableNode } from "../../../tree/nodes/variables/variableNode.js";
11
+ import { parseAlgebraic } from "../../../tree/parsers/latexParser.js";
12
+ const timeUnits = [TimeUnit.h, TimeUnit.min];
13
+ const distanceUnitValues = [DistanceUnit.km, DistanceUnit.m];
14
+ const getAcceptedInputTypesSentence = (identifiers) => {
15
+ const { opts } = identifiers;
16
+ return `Donner le résultat
17
+ ${(() => {
18
+ switch (opts.acceptedInputType) {
19
+ case "exact":
20
+ return "sous forme exacte";
21
+ case "significant(3)":
22
+ return "approché avec $3$ chiffres significatifs";
23
+ }
24
+ })()}.`;
25
+ };
10
26
  const getInstruction = (identifiers) => {
11
- const { distance, time } = identifiers;
27
+ const { distance, time, opts } = identifiers;
12
28
  const distanceMeasure = new Measure(distance.value, 0, distanceUnitValues[distance.unitIndex]);
13
29
  const timeMeasure = new Measure(time.value, 0, timeUnits[time.unitIndex]);
14
30
  const instruction = `Soit un objet parcourant $${distanceMeasure.toTex({
@@ -16,111 +32,166 @@ const getInstruction = (identifiers) => {
16
32
  })}$ en $${timeMeasure.toTex({ notScientific: true })}$.
17
33
 
18
34
 
19
- Caculer la vitesse moyenne de cet objet en $${DistanceUnit.m.toTex()} \\cdot ${TimeUnit.s.toTex()}^{-1}$.
35
+ Calculer la vitesse moyenne de cet objet en $${opts.unitTex}$.
36
+
37
+ ${getAcceptedInputTypesSentence(identifiers)}
20
38
  `;
21
39
  return instruction;
22
40
  };
23
- const getAnswer = (identifiers) => {
24
- const { distance, time } = identifiers;
25
- const distanceMeasure = new Measure(distance.value, 0, distanceUnitValues[distance.unitIndex]);
26
- const timeMeasure = new Measure(time.value, 0, timeUnits[time.unitIndex]);
27
- const answer = distanceMeasure
28
- .convert("m")
29
- .divide(timeMeasure.convert("s"))
30
- .toSignificant(2);
31
- return answer.toTex();
32
- };
33
- const getHint = () => {
41
+ const getHint = ({ opts }) => {
34
42
  return `La vitesse moyenne est donnée par :
35
43
 
36
44
  $$
37
- \\frac{\\text{distance}}{\\text{temps}} \\ \\textrm{m} \\cdot \\textrm{s}^{-1}
45
+ \\frac{\\text{distance}}{\\text{temps}} \\ ${opts.unitTex}
38
46
  $$`;
39
47
  };
40
48
  const getCorrection = (identifiers) => {
41
- const { distance, time } = identifiers;
49
+ const { distance, time, opts } = identifiers;
42
50
  let correction = ``;
43
51
  const distanceMeasure = new Measure(distance.value, 0, distanceUnitValues[distance.unitIndex]).convert("m");
44
52
  const timeMeasure = new Measure(time.value, 0, timeUnits[time.unitIndex]).convert("s");
45
- const calcul = new FractionNode(new VariableNode(distanceMeasure.toSignificant(2).toTex()), new VariableNode(timeMeasure.toSignificant(2).toTex()));
46
- const answer = distanceMeasure.divide(timeMeasure).toSignificant(2).toTex();
53
+ const calcul = new FractionNode(new VariableNode(distanceMeasure.toTex()), new VariableNode(timeMeasure.toTex()));
54
+ const answer = getAnswer(identifiers);
47
55
  if (distance.unitIndex === 0)
48
- correction = `- On convertit les $\\textrm{km}$ en $\\textrm{m}$ : $1\\ \\textrm{km}=1000\\ \\textrm{m}$.`;
56
+ correction = `- On convertit les $\\textrm{km}$ en $\\textrm{m}$ : $1\\ \\textrm{km}=1000\\ \\textrm{m}$.
57
+
58
+ $$
59
+ ${distance.value.frenchify()} \\textrm{km} = ${distance.value.frenchify()} \\times 1000 = ${distanceMeasure.toTex()}
60
+ $$
61
+
62
+ `;
49
63
  switch (time.unitIndex) {
50
64
  case 0:
51
65
  correction = `${correction}
52
- - On convertit les heures en secondes : $1\\ \\textrm{h} = 3600\\ \\textrm{s}$.`;
66
+ - On convertit les heures en secondes : $1\\ \\textrm{h} = 3600\\ \\textrm{s}$.
67
+
68
+ $$
69
+ ${time.value.frenchify()} \\textrm{h} = ${time.value.frenchify()} \\times 3600 = ${timeMeasure.toTex()}
70
+ $$
71
+
72
+ `;
53
73
  break;
54
74
  case 1:
55
75
  default:
56
76
  correction = `${correction}
57
- - On convertit les minutes en secondes : $1\\ \\textrm{m} = 60\\ \\textrm{s}$.`;
77
+ - On convertit les minutes en secondes : $1\\ \\textrm{min} = 60\\ \\textrm{s}$.
78
+
79
+ $$
80
+ ${time.value.frenchify()} \\textrm{min} = ${time.value.frenchify()} \\times 60 = ${timeMeasure.toTex()}
81
+ $$
82
+
83
+ `;
58
84
  }
59
85
  return `${correction}
60
- - On applique la règle de calcul pour la vitesse moyenne : $${calcul.toTex()} = ${answer}$`;
86
+ - On applique la règle de calcul pour la vitesse moyenne : $${calcul.toTex()}$
87
+ - On arrondit à la toute fin : $${calcul.toTex()} \\approx ${answer} \\ ${opts.unitTex}$`;
61
88
  };
62
- const getQuestionFromIdentifiers = (identifiers) => {
63
- const question = {
64
- answer: getAnswer(identifiers),
65
- instruction: getInstruction(identifiers),
66
- keys: [],
67
- hint: getHint(identifiers),
68
- correction: getCorrection(identifiers),
69
- answerFormat: "tex",
70
- identifiers,
71
- };
72
- return question;
89
+ const getAnswer = (identifiers) => {
90
+ return getAnswerMeasure(identifiers).toTex({ hideUnit: true });
73
91
  };
74
- const timeUnits = [TimeUnit.h, TimeUnit.mi];
75
- const distanceUnitValues = [DistanceUnit.km, DistanceUnit.m];
76
- const getAverageSpeedQuestion = () => {
77
- const distance = { value: randint(70, 151), unitIndex: randint(0, 2) };
78
- const time = { value: randint(10, 61), unitIndex: randint(0, 2) };
79
- const identifiers = { distance, time };
80
- return getQuestionFromIdentifiers(identifiers);
92
+ const getAnswerMeasure = (identifiers) => {
93
+ const { distance, time } = identifiers;
94
+ const distanceMeasure = new Measure(distance.value, 0, distanceUnitValues[distance.unitIndex]);
95
+ const timeMeasure = new Measure(time.value, 0, timeUnits[time.unitIndex]);
96
+ return distanceMeasure
97
+ .convert("m")
98
+ .divide(timeMeasure.convert("s"))
99
+ .toSignificant(2);
100
+ };
101
+ const isAnswerValid = (ans, { answer, ...identifiers }) => {
102
+ const ansNode = parseAlgebraic(ans);
103
+ const answerNode = parseAlgebraic(getAnswerMeasure(identifiers).toTex({ hideUnit: true }));
104
+ return substract(ansNode, answerNode).simplify().evaluate() === 0;
81
105
  };
82
- const getPropositions = (n, { answer, distance, time }) => {
106
+ const getPropositions = (n, { answer, distance, time, opts }) => {
83
107
  const propositions = [];
84
- addValidProp(propositions, answer);
108
+ addValidProp(propositions, `${answer} \\ ${opts.unitTex}`);
85
109
  const distanceMeasure = new Measure(distance.value, 0, distanceUnitValues[distance.unitIndex]);
86
110
  const timeMeasure = new Measure(time.value, 0, timeUnits[time.unitIndex]);
87
- genearatePropositions(distanceMeasure, timeMeasure).forEach((value) => tryToAddWrongProp(propositions, value));
111
+ generatePropositions(distanceMeasure, timeMeasure).forEach((value) => tryToAddWrongProp(propositions, `${value} \\ ${opts.unitTex}`));
88
112
  const division = distanceMeasure
89
113
  .convert("m")
90
114
  .divide(timeMeasure.convert("s"));
91
115
  const divisionValue = division.significantPart * division.exponent;
92
116
  propWhile(propositions, n, () => {
93
117
  const random = randfloat(divisionValue - 10, divisionValue + 11);
94
- tryToAddWrongProp(propositions, new Measure(random, 0, division.getUnit()).toSignificant(2).toTex());
118
+ const valueTex = new Measure(random, 0, division.getUnit())
119
+ .toSignificant(2)
120
+ .toTex({ hideUnit: true });
121
+ tryToAddWrongProp(propositions, `${valueTex} \\ ${opts.unitTex}`);
95
122
  });
96
123
  return shuffleProps(propositions, n);
97
124
  };
98
- const genearatePropositions = (distance, time) => {
125
+ const generatePropositions = (distance, time) => {
99
126
  const distanceInMeter = distance.convert("m");
100
127
  const timeInSeconds = time.convert("s");
101
128
  return [
102
- distanceInMeter.times(timeInSeconds).toSignificant(2).toTex(),
103
- distanceInMeter.divide(time).toSignificant(2).toTex(),
104
- distance.divide(timeInSeconds).toSignificant(2).toTex(),
105
- distance.divide(time).toSignificant(2).toTex(),
106
- ];
107
- };
108
- const isAnswerValid = (ans, { answer, distance, time }) => {
109
- const distanceMeasure = new Measure(distance.value, 0, distanceUnitValues[distance.unitIndex]).convert("m");
110
- const timeMeasure = new Measure(time.value, 0, timeUnits[time.unitIndex]).convert("s");
111
- return [
112
- answer,
113
- distanceMeasure
114
- .divide(timeMeasure)
129
+ distanceInMeter
130
+ .times(timeInSeconds)
115
131
  .toSignificant(2)
116
132
  .toTex({ hideUnit: true }),
117
- ].includes(ans);
133
+ distanceInMeter.divide(time).toSignificant(2).toTex({ hideUnit: true }),
134
+ distance.divide(timeInSeconds).toSignificant(2).toTex({ hideUnit: true }),
135
+ distance.divide(time).toSignificant(2).toTex({ hideUnit: true }),
136
+ ];
137
+ };
138
+ const getKeys = () => {
139
+ return [];
140
+ // return [`\\text{m} \\cdot \\text{s}^{-1}`].map((tex) => {
141
+ // return {
142
+ // id: "custom",
143
+ // label: tex,
144
+ // labelType: "raw",
145
+ // mathfieldInstructions: {
146
+ // method: "write",
147
+ // content: tex,
148
+ // },
149
+ // } as KeyProps;
150
+ // });
151
+ };
152
+ const getAverageSpeedQuestion = (optsIn) => {
153
+ const opts = Object.assign(optsDefault, optsIn) ?? optsDefault;
154
+ const distance = { value: randint(70, 151), unitIndex: randint(0, 2) };
155
+ const time = { value: randint(10, 61), unitIndex: randint(0, 2) };
156
+ const identifiers = { distance, time, opts };
157
+ return getQuestionFromIdentifiers(identifiers);
158
+ };
159
+ const getQuestionFromIdentifiers = (identifiers) => {
160
+ const question = {
161
+ answer: getAnswer(identifiers),
162
+ instruction: getInstruction(identifiers),
163
+ keys: getKeys(identifiers),
164
+ hint: getHint(identifiers),
165
+ correction: getCorrection(identifiers),
166
+ answerFormat: "tex",
167
+ identifiers,
168
+ };
169
+ return question;
170
+ };
171
+ const optsDefault = {
172
+ acceptedInputType: "significant(3)",
173
+ unitTex: "\\text{m} \\cdot \\text{s}^{-1}",
118
174
  };
175
+ const options = [
176
+ {
177
+ id: "unitTex",
178
+ label: "Unité utilisée",
179
+ target: GeneratorOptionTarget.generation,
180
+ type: GeneratorOptionType.select,
181
+ values: [
182
+ "\\text{m} \\cdot \\text{s}^{-1}",
183
+ "\\text{m/s}",
184
+ "\\text{s} \\cdot \\text{m}^{-1}",
185
+ ],
186
+ defaultValue: optsDefault.unitTex,
187
+ },
188
+ ];
119
189
  export const averageSpeed = {
120
190
  id: "averageSpeed",
121
- label: "Caclul de vitesse moyenne",
191
+ label: "Calcul de vitesse moyenne",
122
192
  isSingleStep: true,
123
- generator: (nb) => getDistinctQuestions(getAverageSpeedQuestion, nb),
193
+ generator: (nb, opts) => getDistinctQuestions(() => getAverageSpeedQuestion(opts), nb),
194
+ options,
124
195
  qcmTimer: 60,
125
196
  freeTimer: 60,
126
197
  getPropositions,
@@ -1 +1 @@
1
- {"version":3,"file":"averageSpeedCalculation.d.ts","sourceRoot":"","sources":["../../../../src/exercises/pc/motion/averageSpeedCalculation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAeT,MAAM,6BAA6B,CAAC;AAUrC,KAAK,WAAW,GAAG;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,iBAAiB,GAAG,UAAU,GAAG,OAAO,CAAC;CAClD,CAAC;AA6PF,eAAO,MAAM,+BAA+B,EAAE,QAAQ,CAAC,WAAW,CAajE,CAAC"}
1
+ {"version":3,"file":"averageSpeedCalculation.d.ts","sourceRoot":"","sources":["../../../../src/exercises/pc/motion/averageSpeedCalculation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAeT,MAAM,6BAA6B,CAAC;AAUrC,KAAK,WAAW,GAAG;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,iBAAiB,GAAG,UAAU,GAAG,OAAO,CAAC;CAClD,CAAC;AAmQF,eAAO,MAAM,+BAA+B,EAAE,QAAQ,CAAC,WAAW,CAajE,CAAC"}
@@ -42,7 +42,9 @@ const getInstruction = (identifiers) => {
42
42
  Utiliser ces informations pour calculer ${targetVariable.name === "distance" ||
43
43
  targetVariable.name === "vitesse moyenne"
44
44
  ? "la"
45
- : "le"} ${targetVariable.name} en $${targetVariable.value.getUnit().toTex()}$.`;
45
+ : "le"} ${targetVariable.name} en $${targetVariable.value.getUnit().toTex()}$.
46
+
47
+ Donner la réponse sous forme arrondie à $2$ décimales.`;
46
48
  return instruction;
47
49
  };
48
50
  const getAnswer = (identifiers) => {
@@ -83,16 +85,20 @@ const getCorrection = (identifiers) => {
83
85
  const correction = targetVariable.name === "vitesse moyenne"
84
86
  ? `La vitesse moyenne est calculée en utilisant la formule $v = \\frac{d}{\\Delta t}$. Donc, $v = \\frac{${round(distance, 2)
85
87
  .toTree()
86
- .toTex()}}{${round(deltaTime, 2).toTree().toTex()}} = ${new Measure(round(distance / deltaTime, 2), 0, targetVariable.value.getUnit()).toTex({ notScientific: true })}$.`
88
+ .toTex()}}{${round(deltaTime, 2)
89
+ .toTree()
90
+ .toTex()}} \\approx ${new Measure(round(distance / deltaTime, 2), 0, targetVariable.value.getUnit()).toTex({ notScientific: true })}$.`
87
91
  : targetVariable.name === "distance"
88
92
  ? `La distance est calculée en utilisant la formule $d = v \\times \\Delta t$. Donc, $d = ${round(speed, 2)
89
93
  .toTree()
90
94
  .toTex()} \\times ${round(deltaTime, 2)
91
95
  .toTree()
92
- .toTex()} = ${new Measure(round(speed * deltaTime, 2), 0, DistanceUnit.km).toTex({ notScientific: true })}$.`
96
+ .toTex()} \\approx ${new Measure(round(speed * deltaTime, 2), 0, DistanceUnit.km).toTex({ notScientific: true })}$.`
93
97
  : `Le temps est calculé en utilisant la formule $\\Delta t = \\frac{d}{v}$. Donc, $t = \\frac{${round(distance, 2)
94
98
  .toTree()
95
- .toTex()}}{${round(speed, 2).toTree().toTex()}} = ${new Measure(round(distance / speed, 2), 0, TimeUnit.h).toTex({ notScientific: true })}$.`;
99
+ .toTex()}}{${round(speed, 2)
100
+ .toTree()
101
+ .toTex()}} \\approx ${new Measure(round(distance / speed, 2), 0, TimeUnit.h).toTex({ notScientific: true })}$.`;
96
102
  return correction;
97
103
  };
98
104
  const getAnswerNode = (identifiers) => {
@@ -1,8 +1,8 @@
1
1
  import { Exercise } from "../../exercises/exercise.js";
2
2
  type Identifiers = {
3
3
  isAsking: string;
4
- enetringLightX: number;
5
- enetringLightY: number;
4
+ enteringLightX: number;
5
+ enteringLightY: number;
6
6
  };
7
7
  export declare const recognizeRefractionOrReflectionAngles: Exercise<Identifiers>;
8
8
  export {};