math-exercises 3.0.76 → 3.0.78

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 (108) hide show
  1. package/lib/exercises/math/calcul/arithmetics/calculateDistanceWithAbsoluteValue.d.ts +10 -0
  2. package/lib/exercises/math/calcul/arithmetics/calculateDistanceWithAbsoluteValue.d.ts.map +1 -0
  3. package/lib/exercises/math/calcul/arithmetics/calculateDistanceWithAbsoluteValue.js +112 -0
  4. package/lib/exercises/math/calcul/arithmetics/calculateWithAbsoluteValue.d.ts +8 -0
  5. package/lib/exercises/math/calcul/arithmetics/calculateWithAbsoluteValue.d.ts.map +1 -0
  6. package/lib/exercises/math/calcul/arithmetics/calculateWithAbsoluteValue.js +123 -0
  7. package/lib/exercises/math/calcul/arithmetics/compareInverseValues.d.ts +10 -0
  8. package/lib/exercises/math/calcul/arithmetics/compareInverseValues.d.ts.map +1 -0
  9. package/lib/exercises/math/calcul/arithmetics/compareInverseValues.js +136 -0
  10. package/lib/exercises/math/calcul/arithmetics/compareSquaredValues.d.ts +9 -0
  11. package/lib/exercises/math/calcul/arithmetics/compareSquaredValues.d.ts.map +1 -0
  12. package/lib/exercises/math/calcul/arithmetics/compareSquaredValues.js +143 -0
  13. package/lib/exercises/math/calcul/arithmetics/index.d.ts +5 -0
  14. package/lib/exercises/math/calcul/arithmetics/index.d.ts.map +1 -1
  15. package/lib/exercises/math/calcul/arithmetics/index.js +5 -0
  16. package/lib/exercises/math/calcul/arithmetics/sqrtInequality.d.ts +10 -0
  17. package/lib/exercises/math/calcul/arithmetics/sqrtInequality.d.ts.map +1 -0
  18. package/lib/exercises/math/calcul/arithmetics/sqrtInequality.js +160 -0
  19. package/lib/exercises/math/calcul/sign/absoluteNumber.js +1 -1
  20. package/lib/exercises/math/functions/absolute/absoluteValueInequations.d.ts.map +1 -1
  21. package/lib/exercises/math/functions/absolute/absoluteValueInequations.js +5 -1
  22. package/lib/exercises/math/functions/basics/graphicEquation.d.ts.map +1 -1
  23. package/lib/exercises/math/functions/basics/graphicEquation.js +33 -1
  24. package/lib/exercises/math/functions/basics/twoFunctionsEquation.d.ts.map +1 -1
  25. package/lib/exercises/math/functions/basics/twoFunctionsEquation.js +27 -0
  26. package/lib/exercises/math/functions/cube/compareCubeValues.d.ts +8 -0
  27. package/lib/exercises/math/functions/cube/compareCubeValues.d.ts.map +1 -0
  28. package/lib/exercises/math/functions/cube/compareCubeValues.js +113 -0
  29. package/lib/exercises/math/functions/cube/index.d.ts +1 -0
  30. package/lib/exercises/math/functions/cube/index.d.ts.map +1 -1
  31. package/lib/exercises/math/functions/cube/index.js +1 -0
  32. package/lib/exercises/math/functions/index.d.ts +1 -0
  33. package/lib/exercises/math/functions/index.d.ts.map +1 -1
  34. package/lib/exercises/math/functions/index.js +1 -0
  35. package/lib/exercises/math/functions/sqrt/compareSqrtValues.d.ts +8 -0
  36. package/lib/exercises/math/functions/sqrt/compareSqrtValues.d.ts.map +1 -0
  37. package/lib/exercises/math/functions/sqrt/compareSqrtValues.js +83 -0
  38. package/lib/exercises/math/functions/sqrt/index.d.ts +2 -0
  39. package/lib/exercises/math/functions/sqrt/index.d.ts.map +1 -0
  40. package/lib/exercises/math/functions/sqrt/index.js +1 -0
  41. package/lib/exercises/math/functions/variations/varTableExtremaReading.d.ts.map +1 -1
  42. package/lib/exercises/math/functions/variations/varTableExtremaReading.js +23 -8
  43. package/lib/exercises/math/geometry/angles/index.d.ts +1 -0
  44. package/lib/exercises/math/geometry/angles/index.d.ts.map +1 -1
  45. package/lib/exercises/math/geometry/angles/index.js +1 -0
  46. package/lib/exercises/math/geometry/angles/parallelogramFourthAngle.d.ts +8 -0
  47. package/lib/exercises/math/geometry/angles/parallelogramFourthAngle.d.ts.map +1 -0
  48. package/lib/exercises/math/geometry/angles/parallelogramFourthAngle.js +92 -0
  49. package/lib/exercises/math/geometry/cartesian/placeAbscissOnLine.d.ts.map +1 -1
  50. package/lib/exercises/math/geometry/cartesian/placeAbscissOnLine.js +26 -1
  51. package/lib/exercises/math/geometry/euclidian/pythagoreOrThales.d.ts.map +1 -1
  52. package/lib/exercises/math/geometry/euclidian/pythagoreOrThales.js +47 -13
  53. package/lib/exercises/math/geometry/lines/linesRelativePositions.d.ts.map +1 -1
  54. package/lib/exercises/math/geometry/lines/linesRelativePositions.js +29 -5
  55. package/lib/exercises/math/probaStat/calculateMeanFromFrequencies.d.ts +8 -0
  56. package/lib/exercises/math/probaStat/calculateMeanFromFrequencies.d.ts.map +1 -0
  57. package/lib/exercises/math/probaStat/calculateMeanFromFrequencies.js +108 -0
  58. package/lib/exercises/math/probaStat/checkEquiprobability.d.ts +9 -0
  59. package/lib/exercises/math/probaStat/checkEquiprobability.d.ts.map +1 -0
  60. package/lib/exercises/math/probaStat/checkEquiprobability.js +129 -0
  61. package/lib/exercises/math/probaStat/getComplementaryProbability.d.ts +7 -0
  62. package/lib/exercises/math/probaStat/getComplementaryProbability.d.ts.map +1 -0
  63. package/lib/exercises/math/probaStat/getComplementaryProbability.js +90 -0
  64. package/lib/exercises/math/probaStat/getMissingProbabilityValue.d.ts +9 -0
  65. package/lib/exercises/math/probaStat/getMissingProbabilityValue.d.ts.map +1 -0
  66. package/lib/exercises/math/probaStat/getMissingProbabilityValue.js +109 -0
  67. package/lib/exercises/math/probaStat/index.d.ts +6 -0
  68. package/lib/exercises/math/probaStat/index.d.ts.map +1 -1
  69. package/lib/exercises/math/probaStat/index.js +6 -0
  70. package/lib/exercises/math/probaStat/mostLeastProbable.d.ts +8 -0
  71. package/lib/exercises/math/probaStat/mostLeastProbable.d.ts.map +1 -0
  72. package/lib/exercises/math/probaStat/mostLeastProbable.js +114 -0
  73. package/lib/exercises/math/probaStat/unionIntersectionProba.d.ts +11 -0
  74. package/lib/exercises/math/probaStat/unionIntersectionProba.d.ts.map +1 -0
  75. package/lib/exercises/math/probaStat/unionIntersectionProba.js +164 -0
  76. package/lib/exercises/math/python/conditionIfElifElse.d.ts +9 -0
  77. package/lib/exercises/math/python/conditionIfElifElse.d.ts.map +1 -0
  78. package/lib/exercises/math/python/conditionIfElifElse.js +121 -0
  79. package/lib/exercises/math/python/index.d.ts +1 -0
  80. package/lib/exercises/math/python/index.d.ts.map +1 -1
  81. package/lib/exercises/math/python/index.js +1 -0
  82. package/lib/exercises/math/python/pyNestedForLoopExercise.d.ts.map +1 -1
  83. package/lib/exercises/math/python/pyNestedForLoopExercise.js +26 -10
  84. package/lib/exercises/math/python/pyWhileLoop1Exercise.d.ts +0 -1
  85. package/lib/exercises/math/python/pyWhileLoop1Exercise.d.ts.map +1 -1
  86. package/lib/exercises/math/python/pyWhileLoop1Exercise.js +54 -31
  87. package/lib/exercises/math/python/pythonFunctionTrinom.d.ts.map +1 -1
  88. package/lib/exercises/math/python/pythonFunctionTrinom.js +23 -1
  89. package/lib/exercises/math/python/whileLoop.js +2 -2
  90. package/lib/exercises/math/python/whileLoopCount.js +1 -1
  91. package/lib/exercises/math/sequences/explicitFormulaUsage.js +3 -3
  92. package/lib/exercises/math/sequences/genericSequenceVariations.js +2 -2
  93. package/lib/exercises/math/sets/index.d.ts +2 -0
  94. package/lib/exercises/math/sets/index.d.ts.map +1 -1
  95. package/lib/exercises/math/sets/index.js +2 -0
  96. package/lib/exercises/math/sets/nameOfNumberSets.d.ts +8 -0
  97. package/lib/exercises/math/sets/nameOfNumberSets.d.ts.map +1 -0
  98. package/lib/exercises/math/sets/nameOfNumberSets.js +125 -0
  99. package/lib/exercises/math/sets/subsetsOfKnownSets.d.ts +8 -0
  100. package/lib/exercises/math/sets/subsetsOfKnownSets.d.ts.map +1 -0
  101. package/lib/exercises/math/sets/subsetsOfKnownSets.js +99 -0
  102. package/lib/index.d.ts +61 -6
  103. package/lib/index.d.ts.map +1 -1
  104. package/lib/latexTester.d.ts.map +1 -1
  105. package/lib/latexTester.js +25 -7
  106. package/lib/tests/pdfExo.test.d.ts.map +1 -1
  107. package/lib/tests/pdfExo.test.js +2 -2
  108. package/package.json +1 -1
@@ -0,0 +1,90 @@
1
+ import { addValidProp, shuffleProps, tryToAddWrongProp, } from "../../../exercises/exercise.js";
2
+ import { getDistinctQuestions } from "../../../exercises/utils/getDistinctQuestions.js";
3
+ import { handleVEAError } from "../../../utils/errors/handleVEAError.js";
4
+ import { randfloat } from "../../../math/utils/random/randfloat.js";
5
+ import { round } from "../../../math/utils/round.js";
6
+ import { parseAlgebraic } from "../../../tree/parsers/latexParser.js";
7
+ const getPropositions = (n, { answer }) => {
8
+ const propositions = [];
9
+ addValidProp(propositions, answer);
10
+ while (propositions.length < n) {
11
+ const wrongVal = randfloat(0.1, 0.95, 2);
12
+ tryToAddWrongProp(propositions, wrongVal.frenchify());
13
+ }
14
+ return shuffleProps(propositions, n);
15
+ };
16
+ const getAnswer = ({ pA }) => {
17
+ return round(1 - pA, 2).frenchify();
18
+ };
19
+ const getInstruction = ({ pA }) => {
20
+ return `Soit $A$ un événement tel que $P(A) = ${pA.frenchify()}$.
21
+
22
+ Que vaut la probabilité $P(\\overline A)$ ?`;
23
+ };
24
+ const getHint = () => {
25
+ return `La probabilité de l'évènement complémentaire $\\overline{A}$ s'obtient par la formule :
26
+
27
+ $$
28
+ P(\\overline A) = 1 - P(A)
29
+ $$`;
30
+ };
31
+ const getCorrection = ({ pA }) => {
32
+ const answer = getAnswer({ pA });
33
+ return `La probabilité de l'évènement complémentaire $\\overline{A}$ s'obtient par la formule :
34
+
35
+ $$
36
+ P(\\overline A) = 1 - P(A)
37
+ $$
38
+
39
+ Ici, on a donc :
40
+
41
+ $$
42
+ P(\\overline A) = 1 - ${pA.frenchify()} = ${answer}
43
+ $$`;
44
+ };
45
+ const getKeys = () => {
46
+ return [];
47
+ };
48
+ const isAnswerValid = (ans, { answer }) => {
49
+ try {
50
+ const ansNode = parseAlgebraic(ans);
51
+ const answerNode = parseAlgebraic(answer);
52
+ return ansNode.simplify().equals(answerNode.simplify());
53
+ }
54
+ catch (err) {
55
+ return handleVEAError(err);
56
+ }
57
+ };
58
+ const getGetComplementaryProbabilityQuestion = () => {
59
+ const pA = randfloat(0.1, 0.99, 2);
60
+ const identifiers = { pA };
61
+ return getQuestionFromIdentifiers(identifiers);
62
+ };
63
+ const getQuestionFromIdentifiers = (identifiers) => {
64
+ return {
65
+ answer: getAnswer(identifiers),
66
+ instruction: getInstruction(identifiers),
67
+ keys: getKeys(identifiers),
68
+ answerFormat: "tex",
69
+ identifiers,
70
+ hint: getHint(identifiers),
71
+ correction: getCorrection(identifiers),
72
+ };
73
+ };
74
+ export const getComplementaryProbability = {
75
+ id: "getComplementaryProbability",
76
+ label: "Calculer la probabilité d'un évènement complémentaire",
77
+ isSingleStep: true,
78
+ generator: (nb, opts) => getDistinctQuestions(() => getGetComplementaryProbabilityQuestion(opts), nb),
79
+ qcmTimer: 60,
80
+ freeTimer: 60,
81
+ getPropositions,
82
+ isAnswerValid,
83
+ subject: "Mathématiques",
84
+ getInstruction,
85
+ getHint,
86
+ getCorrection,
87
+ getAnswer,
88
+ getQuestionFromIdentifiers,
89
+ hasHintAndCorrection: true,
90
+ };
@@ -0,0 +1,9 @@
1
+ import { Exercise } from "../../../exercises/exercise.js";
2
+ type Identifiers = {
3
+ labels: string[];
4
+ pValues: number[];
5
+ missingIndex: number;
6
+ };
7
+ export declare const getMissingProbabilityValue: Exercise<Identifiers>;
8
+ export {};
9
+ //# sourceMappingURL=getMissingProbabilityValue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getMissingProbabilityValue.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/probaStat/getMissingProbabilityValue.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAcT,MAAM,6BAA6B,CAAC;AASrC,KAAK,WAAW,GAAG;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAiHF,eAAO,MAAM,0BAA0B,EAAE,QAAQ,CAAC,WAAW,CAiB5D,CAAC"}
@@ -0,0 +1,109 @@
1
+ import { addValidProp, tryToAddWrongProp, shuffleProps, } from "../../../exercises/exercise.js";
2
+ import { getDistinctQuestions } from "../../../exercises/utils/getDistinctQuestions.js";
3
+ import { handleVEAError } from "../../../utils/errors/handleVEAError.js";
4
+ import { randfloat } from "../../../math/utils/random/randfloat.js";
5
+ import { round } from "../../../math/utils/round.js";
6
+ import { dollarize } from "../../../utils/latex/dollarize.js";
7
+ import { mdTable } from "../../../utils/markdown/mdTable.js";
8
+ import { parseAlgebraic } from "../../../tree/parsers/latexParser.js";
9
+ const getPropositions = (n, { answer }) => {
10
+ const props = [];
11
+ addValidProp(props, answer);
12
+ while (props.length < n) {
13
+ const numeric = answer.unfrenchify();
14
+ const offset = randfloat(-0.2, 0.2, 2);
15
+ const candidate = round(numeric + offset, 2).frenchify();
16
+ tryToAddWrongProp(props, candidate);
17
+ }
18
+ return shuffleProps(props, n);
19
+ };
20
+ const getAnswer = ({ pValues, missingIndex }) => {
21
+ return pValues[missingIndex].frenchify();
22
+ };
23
+ const getInstruction = ({ labels, pValues, missingIndex, }) => {
24
+ return `Quelle est la valeur manquante dans la loi de probabilité suivante ?
25
+
26
+ ${mdTable([
27
+ ["Issue", ...labels.map((l) => dollarize(l))],
28
+ [
29
+ "Probabilité",
30
+ ...pValues.map((p, i) => i === missingIndex ? "..." : dollarize(p.frenchify())),
31
+ ],
32
+ ])}`;
33
+ };
34
+ const getHint = () => {
35
+ return `La somme des probabilités d'une loi de probabilité est égale à $1$.`;
36
+ };
37
+ const getCorrection = ({ labels, pValues, missingIndex, }) => {
38
+ const knownTerms = labels
39
+ .map((l, i) => (i === missingIndex ? null : pValues[i].frenchify()))
40
+ .filter(Boolean)
41
+ .join("+");
42
+ const sumKnown = round(pValues.filter((_, i) => i !== missingIndex).reduce((s, v) => s + v, 0), 2);
43
+ const missing = round(1 - sumKnown, 2);
44
+ return `
45
+ On additionne les probabilités connues :
46
+
47
+ $$
48
+ ${knownTerms} = ${sumKnown.frenchify()}
49
+ $$
50
+
51
+ Puisque la somme des probabilités d'une loi de probabilité vaut $1$, on peut en déduire la probabilité manquante :
52
+
53
+
54
+ $$
55
+ P(${labels[missingIndex]}) = 1 - ${sumKnown.frenchify()} = ${missing.frenchify()}.
56
+ $$
57
+ `;
58
+ };
59
+ const getKeys = () => {
60
+ return [];
61
+ };
62
+ const isAnswerValid = (ans, { answer }) => {
63
+ try {
64
+ const a = parseAlgebraic(ans);
65
+ const b = parseAlgebraic(answer);
66
+ return a.simplify().equals(b.simplify());
67
+ }
68
+ catch (err) {
69
+ return handleVEAError(err);
70
+ }
71
+ };
72
+ const getGetMissingProbabilityValueQuestion = () => {
73
+ const labels = ["A", "B", "C", "D", "E"];
74
+ const raw = labels.map(() => Math.random());
75
+ const total = raw.reduce((s, v) => s + v, 0);
76
+ let pValues = raw.map((v) => round(v / total, 2));
77
+ // ajustement pour que la somme fasse exactement 1
78
+ const sumRounded = pValues.reduce((s, v) => s + v, 0);
79
+ const diff = round(1 - sumRounded, 2);
80
+ pValues[pValues.length - 1] = round(pValues[pValues.length - 1] + diff, 2);
81
+ const missingIndex = Math.floor(Math.random() * labels.length);
82
+ return getQuestionFromIdentifiers({ labels, pValues, missingIndex });
83
+ };
84
+ const getQuestionFromIdentifiers = (identifiers) => ({
85
+ answer: getAnswer(identifiers),
86
+ instruction: getInstruction(identifiers),
87
+ keys: getKeys(identifiers),
88
+ answerFormat: "tex",
89
+ identifiers,
90
+ hint: getHint(identifiers),
91
+ correction: getCorrection(identifiers),
92
+ });
93
+ export const getMissingProbabilityValue = {
94
+ id: "getMissingProbabilityValue",
95
+ label: "Calculer une valeur manquante dans une loi de probabilité",
96
+ isSingleStep: true,
97
+ generator: (nb, opts) => getDistinctQuestions(() => getGetMissingProbabilityValueQuestion(opts), nb),
98
+ qcmTimer: 60,
99
+ freeTimer: 60,
100
+ getPropositions,
101
+ isAnswerValid,
102
+ subject: "Mathématiques",
103
+ getInstruction,
104
+ getHint,
105
+ getCorrection,
106
+ getAnswer,
107
+ getQuestionFromIdentifiers,
108
+ hasHintAndCorrection: true,
109
+ };
@@ -12,4 +12,10 @@ export * from "./probaFromTableWithContext.js";
12
12
  export * from "./binomial/index.js";
13
13
  export * from "./basicStats/index.js";
14
14
  export * from "./randomVariable/index.js";
15
+ export * from "./getMissingProbabilityValue.js";
16
+ export * from "./getComplementaryProbability.js";
17
+ export * from "./unionIntersectionProba.js";
18
+ export * from "./calculateMeanFromFrequencies.js";
19
+ export * from "./mostLeastProbable.js";
20
+ export * from "./checkEquiprobability.js";
15
21
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/probaStat/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/probaStat/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,kCAAkC,CAAC;AACjD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mCAAmC,CAAC;AAClD,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC"}
@@ -12,3 +12,9 @@ export * from "./probaFromTableWithContext.js";
12
12
  export * from "./binomial/index.js";
13
13
  export * from "./basicStats/index.js";
14
14
  export * from "./randomVariable/index.js";
15
+ export * from "./getMissingProbabilityValue.js";
16
+ export * from "./getComplementaryProbability.js";
17
+ export * from "./unionIntersectionProba.js";
18
+ export * from "./calculateMeanFromFrequencies.js";
19
+ export * from "./mostLeastProbable.js";
20
+ export * from "./checkEquiprobability.js";
@@ -0,0 +1,8 @@
1
+ import { Exercise } from "../../../exercises/exercise.js";
2
+ import { NodeIdentifiers } from "../../../tree/nodes/nodeConstructor.js";
3
+ export type Identifiers = {
4
+ numericValues: NodeIdentifiers[];
5
+ isMax: boolean;
6
+ };
7
+ export declare const mostLeastProbable: Exercise<Identifiers>;
8
+ //# sourceMappingURL=mostLeastProbable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mostLeastProbable.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/probaStat/mostLeastProbable.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAcT,MAAM,6BAA6B,CAAC;AAMrC,OAAO,EACL,eAAe,EAEhB,MAAM,qCAAqC,CAAC;AAM7C,MAAM,MAAM,WAAW,GAAG;IACxB,aAAa,EAAE,eAAe,EAAE,CAAC;IACjC,KAAK,EAAE,OAAO,CAAC;CAChB,CAAC;AA2HF,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,WAAW,CAkBnD,CAAC"}
@@ -0,0 +1,114 @@
1
+ import { addValidProp, tryToAddWrongProp, shuffleProps, } from "../../../exercises/exercise.js";
2
+ import { getDistinctQuestions } from "../../../exercises/utils/getDistinctQuestions.js";
3
+ import { RationalConstructor } from "../../../math/numbers/rationals/rational.js";
4
+ import { randfloat } from "../../../math/utils/random/randfloat.js";
5
+ import { handleVEAError } from "../../../utils/errors/handleVEAError.js";
6
+ import { coinFlip } from "../../../utils/alea/coinFlip.js";
7
+ import { reifyAlgebraic, } from "../../../tree/nodes/nodeConstructor.js";
8
+ import { round } from "../../../math/utils/round.js";
9
+ import { approxOrEqual } from "../../../utils/latex/approxOrEqual.js";
10
+ import { multiply } from "../../../tree/nodes/operators/multiplyNode.js";
11
+ const getPropositions = (n, { answer }) => {
12
+ const allLabels = ["J", "R", "V"];
13
+ const props = [];
14
+ addValidProp(props, answer);
15
+ for (const label of allLabels) {
16
+ tryToAddWrongProp(props, label);
17
+ }
18
+ return shuffleProps(props, n);
19
+ };
20
+ const getAnswer = ({ numericValues, isMax }) => {
21
+ const numericValuesParsed = numericValues.map((v) => reifyAlgebraic(v).evaluate());
22
+ const targetValue = isMax
23
+ ? Math.max(...numericValuesParsed)
24
+ : Math.min(...numericValuesParsed);
25
+ const index = numericValuesParsed.indexOf(targetValue);
26
+ return ["J", "R", "V"][index];
27
+ };
28
+ const getInstruction = ({ numericValues, isMax, }) => {
29
+ const labels = ["$J$", "$R$", "$V$"];
30
+ const displayValues = numericValues.map((v, i) => {
31
+ if (labels[i] === "$R$") {
32
+ const pct = round(reifyAlgebraic(v).evaluate() * 100, 6);
33
+ return `${pct.frenchify()}\\%`;
34
+ }
35
+ else {
36
+ return reifyAlgebraic(v).toTex();
37
+ }
38
+ });
39
+ const header = `Une expérience aléatoire a trois issues : ${labels.join(", ")}.
40
+
41
+ Leurs probabilités sont respectivement $${displayValues[0]}$ , $${displayValues[1]}$ et $${displayValues[2]}$.\n\n`;
42
+ return header + `Quelle issue est la ${isMax ? "plus" : "moins"} probable ?`;
43
+ };
44
+ const getHint = () => {
45
+ return "Convertis les probabilités dans le même format pour les comparer.";
46
+ };
47
+ const getCorrection = ({ numericValues, isMax, }) => {
48
+ const fraction = reifyAlgebraic(numericValues[0]);
49
+ const percent = reifyAlgebraic(numericValues[1]);
50
+ const evaluatedValues = numericValues.map((v) => round(reifyAlgebraic(v).evaluate(), 2));
51
+ const sortedAsc = [...evaluatedValues].sort((a, b) => a - b);
52
+ const target = isMax ? "plus" : "moins";
53
+ const result = getAnswer({ numericValues, isMax });
54
+ return `On convertit le pourcentage et la fraction en nombres décimaux (éventuellement avec une valeur approchée) pour pouvoir les comparer :
55
+
56
+ - $${fraction.toTex()} ${approxOrEqual(fraction.evaluate(), 2).join("")}$
57
+
58
+ - $${multiply(percent, 100).simplify().toTex()}\\% = ${percent.toTex()}$
59
+
60
+ Puisque $${sortedAsc
61
+ .map((e) => e.frenchify())
62
+ .join("\\leq")}$, l'issue la ${target} probable est donc $${result}$.`;
63
+ };
64
+ const getKeys = () => [];
65
+ const isAnswerValid = (ans, { answer }) => {
66
+ try {
67
+ return ans.trim() === answer;
68
+ }
69
+ catch (err) {
70
+ return handleVEAError(err);
71
+ }
72
+ };
73
+ const getMostLeastProbableQuestion = (opts) => {
74
+ let numericValues = [];
75
+ do {
76
+ numericValues = [
77
+ RationalConstructor.randomIrreductibleProba().toTree(),
78
+ randfloat(0.1, 0.9, 2).toTree(),
79
+ randfloat(0.1, 0.9, 2).toTree(),
80
+ ];
81
+ } while (numericValues.some((e, i) => numericValues.some((e2, i2) => i2 !== i && round(e2.evaluate(), 2) === round(e.evaluate(), 2))));
82
+ const isMax = coinFlip();
83
+ return getQuestionFromIdentifiers({
84
+ numericValues: numericValues.map((e) => e.toIdentifiers()),
85
+ isMax,
86
+ });
87
+ };
88
+ const getQuestionFromIdentifiers = (identifiers) => ({
89
+ answer: getAnswer(identifiers),
90
+ instruction: getInstruction(identifiers),
91
+ keys: getKeys(identifiers),
92
+ answerFormat: "tex",
93
+ identifiers,
94
+ hint: getHint(identifiers),
95
+ correction: getCorrection(identifiers),
96
+ });
97
+ export const mostLeastProbable = {
98
+ id: "mostLeastProbable",
99
+ label: "Identifier l'issue la plus ou la moins probable",
100
+ isSingleStep: true,
101
+ generator: (nb, opts) => getDistinctQuestions(() => getMostLeastProbableQuestion(opts), nb),
102
+ qcmTimer: 60,
103
+ freeTimer: 60,
104
+ getPropositions,
105
+ isAnswerValid,
106
+ subject: "Mathématiques",
107
+ getInstruction,
108
+ getHint,
109
+ getCorrection,
110
+ getAnswer,
111
+ getQuestionFromIdentifiers,
112
+ hasHintAndCorrection: true,
113
+ answerType: "QCU",
114
+ };
@@ -0,0 +1,11 @@
1
+ import { Exercise } from "../../../exercises/exercise.js";
2
+ type Identifiers = {
3
+ pA: number;
4
+ pB: number;
5
+ pUnion: number;
6
+ pIntersection: number;
7
+ target: "pA" | "pB" | "pUnion" | "pIntersection";
8
+ };
9
+ export declare const unionIntersectionProba: Exercise<Identifiers>;
10
+ export {};
11
+ //# sourceMappingURL=unionIntersectionProba.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unionIntersectionProba.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/probaStat/unionIntersectionProba.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAeT,MAAM,6BAA6B,CAAC;AAYrC,KAAK,WAAW,GAAG;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,IAAI,GAAG,IAAI,GAAG,QAAQ,GAAG,eAAe,CAAC;CAClD,CAAC;AAsKF,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAAC,WAAW,CAkBxD,CAAC"}
@@ -0,0 +1,164 @@
1
+ import { addValidProp, shuffleProps, tryToAddWrongProp, } from "../../../exercises/exercise.js";
2
+ import { getDistinctQuestions } from "../../../exercises/utils/getDistinctQuestions.js";
3
+ import { handleVEAError } from "../../../utils/errors/handleVEAError.js";
4
+ import { randfloat } from "../../../math/utils/random/randfloat.js";
5
+ import { round } from "../../../math/utils/round.js";
6
+ import { parseAlgebraic } from "../../../tree/parsers/latexParser.js";
7
+ import { random } from "../../../utils/alea/random.js";
8
+ import { alignTex } from "../../../utils/latex/alignTex.js";
9
+ const getPropositions = (n, { answer }) => {
10
+ const propositions = [];
11
+ addValidProp(propositions, answer);
12
+ while (propositions.length < n) {
13
+ const offset = randfloat(-0.2, 0.2, 2);
14
+ const wrongVal = answer.unfrenchify() + offset;
15
+ tryToAddWrongProp(propositions, round(wrongVal, 2).frenchify());
16
+ }
17
+ return shuffleProps(propositions, n);
18
+ };
19
+ const getAnswer = ({ pA, pB, pUnion, pIntersection, target, }) => {
20
+ let result;
21
+ switch (target) {
22
+ case "pA":
23
+ result = pUnion + pIntersection - pB;
24
+ break;
25
+ case "pB":
26
+ result = pUnion + pIntersection - pA;
27
+ break;
28
+ case "pUnion":
29
+ result = pA + pB - pIntersection;
30
+ break;
31
+ case "pIntersection":
32
+ result = pA + pB - pUnion;
33
+ break;
34
+ }
35
+ return round(result, 2).frenchify();
36
+ };
37
+ const getInstruction = ({ pA, pB, pUnion, pIntersection, target, }) => {
38
+ const vals = {
39
+ pA: pA.frenchify(),
40
+ pB: pB.frenchify(),
41
+ pUnion: pUnion.frenchify(),
42
+ pIntersection: pIntersection.frenchify(),
43
+ };
44
+ let instruction = `Soit $A$ et $B$ deux événements tels que :\n\n`;
45
+ const texts = {
46
+ pA: `$P(B)=${vals.pB}$, $P(A\\cup B)=${vals.pUnion}$ et $P(A\\cap B)=${vals.pIntersection}$.\n\n Calculer $P(A)$.`,
47
+ pB: `$P(A)=${vals.pA}$, $P(A\\cup B)=${vals.pUnion}$ et $P(A\\cap B)=${vals.pIntersection}$.\n\n Calculer $P(B)$.`,
48
+ pUnion: `$P(A)=${vals.pA}$, $P(B)=${vals.pB}$ et $P(A\\cap B)=${vals.pIntersection}$.\n\n Calculer $P(A\\cup B)$.`,
49
+ pIntersection: `$P(A)=${vals.pA}$, $P(B)=${vals.pB}$ et $P(A\\cup B)=${vals.pUnion}$.\n\n Calculer $P(A\\cap B)$.`,
50
+ };
51
+ return instruction + texts[target];
52
+ };
53
+ const getHint = ({ target }) => {
54
+ return `Utilise la formule :
55
+
56
+ $$
57
+ P(A \\cup B) = P(A) + P(B) - P(A \\cap B)
58
+ $$`;
59
+ };
60
+ const getCorrection = (identifiers) => {
61
+ const { pA, pB, pUnion, pIntersection, target } = identifiers;
62
+ const fmt = {
63
+ pA: pA.frenchify(),
64
+ pB: pB.frenchify(),
65
+ pUnion: pUnion.frenchify(),
66
+ pIntersection: pIntersection.frenchify(),
67
+ };
68
+ let explanation = `On utilise la formule :
69
+
70
+ $$
71
+ P(A \\cup B) = P(A) + P(B) - P(A \\cap B)
72
+ $$
73
+
74
+ Ici on a donc : \n `;
75
+ switch (target) {
76
+ case "pA":
77
+ explanation += `
78
+ ${alignTex([
79
+ ["P(A)", "=", "P(A\\cup B) + P(A\\cap B) - P(B)"],
80
+ ["", "=", `${fmt.pUnion} + ${fmt.pIntersection} - ${fmt.pB}`],
81
+ ["", "=", getAnswer(identifiers)],
82
+ ])}`;
83
+ break;
84
+ case "pB":
85
+ explanation += `
86
+ ${alignTex([
87
+ ["P(B)", "=", "P(A\\cup B) + P(A\\cap B) - P(A)"],
88
+ ["", "=", `${fmt.pUnion} + ${fmt.pIntersection} - ${fmt.pA}`],
89
+ ["", "=", getAnswer(identifiers)],
90
+ ])}`;
91
+ break;
92
+ case "pUnion":
93
+ explanation += `
94
+ ${alignTex([
95
+ ["P(A\\cup B)", "=", "P(A) + P(B) - P(A\\cap B)"],
96
+ ["", "=", `${fmt.pA} + ${fmt.pB} - ${fmt.pIntersection}`],
97
+ ["", "=", getAnswer(identifiers)],
98
+ ])}`;
99
+ break;
100
+ case "pIntersection":
101
+ explanation += `
102
+ ${alignTex([
103
+ ["P(A\\cap B)", "=", "P(A) + P(B) - P(A\\cup B)"],
104
+ ["", "=", `${fmt.pA} + ${fmt.pB} - ${fmt.pUnion}`],
105
+ ["", "=", getAnswer(identifiers)],
106
+ ])}`;
107
+ break;
108
+ }
109
+ return explanation;
110
+ };
111
+ const getKeys = () => [];
112
+ const isAnswerValid = (ans, { answer }) => {
113
+ try {
114
+ const ansNode = parseAlgebraic(ans);
115
+ const answerNode = parseAlgebraic(answer);
116
+ return ansNode.simplify().equals(answerNode.simplify());
117
+ }
118
+ catch (err) {
119
+ return handleVEAError(err);
120
+ }
121
+ };
122
+ const getUnionIntersectionProbaQuestion = (ops) => {
123
+ const pA = randfloat(0.1, 0.8, 2);
124
+ const pB = randfloat(0.1, 0.8, 2);
125
+ const maxIntersection = Math.min(pA, pB);
126
+ const minIntersection = Math.max(0, round(pA + pB - 1, 2));
127
+ const pIntersection = randfloat(minIntersection, maxIntersection, 2);
128
+ const pUnion = round(pA + pB - pIntersection, 2);
129
+ const targets = [
130
+ "pA",
131
+ "pB",
132
+ "pUnion",
133
+ "pIntersection",
134
+ ];
135
+ const target = random(targets);
136
+ const identifiers = { pA, pB, pUnion, pIntersection, target };
137
+ return getQuestionFromIdentifiers(identifiers);
138
+ };
139
+ const getQuestionFromIdentifiers = (identifiers) => ({
140
+ answer: getAnswer(identifiers),
141
+ instruction: getInstruction(identifiers),
142
+ keys: getKeys(identifiers),
143
+ answerFormat: "tex",
144
+ identifiers,
145
+ hint: getHint(identifiers),
146
+ correction: getCorrection(identifiers),
147
+ });
148
+ export const unionIntersectionProba = {
149
+ id: "unionIntersectionProba",
150
+ label: "Calculer une probabilité via les formules de l’union et de l’intersection",
151
+ isSingleStep: true,
152
+ generator: (nb, opts) => getDistinctQuestions(() => getUnionIntersectionProbaQuestion(opts), nb),
153
+ qcmTimer: 60,
154
+ freeTimer: 60,
155
+ getPropositions,
156
+ isAnswerValid,
157
+ subject: "Mathématiques",
158
+ getInstruction,
159
+ getHint,
160
+ getCorrection,
161
+ getAnswer,
162
+ getQuestionFromIdentifiers,
163
+ hasHintAndCorrection: true,
164
+ };
@@ -0,0 +1,9 @@
1
+ import { Exercise } from "../../../exercises/exercise.js";
2
+ type Identifiers = {
3
+ a: number;
4
+ b: number;
5
+ opName: string;
6
+ };
7
+ export declare const conditionIfElifElse: Exercise<Identifiers>;
8
+ export {};
9
+ //# sourceMappingURL=conditionIfElifElse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conditionIfElifElse.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/python/conditionIfElifElse.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAcT,MAAM,6BAA6B,CAAC;AAKrC,KAAK,WAAW,GAAG;IACjB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AA+HF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,WAAW,CAcrD,CAAC"}