math-exercises 3.0.151 → 3.0.153

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 (199) hide show
  1. package/lib/exercises/exercise.d.ts +7 -0
  2. package/lib/exercises/exercise.d.ts.map +1 -1
  3. package/lib/exercises/math/calcul/fractions/fractionToPercentToDecimal.d.ts +5 -1
  4. package/lib/exercises/math/calcul/fractions/fractionToPercentToDecimal.d.ts.map +1 -1
  5. package/lib/exercises/math/calcul/fractions/fractionToPercentToDecimal.js +92 -38
  6. package/lib/exercises/math/calcul/proportionality/findCoeffInProportionalTableNonIntegers.d.ts.map +1 -1
  7. package/lib/exercises/math/calcul/proportionality/findCoeffInProportionalTableNonIntegers.js +5 -1
  8. package/lib/exercises/math/calcul/proportionality/isTableProportional.d.ts.map +1 -1
  9. package/lib/exercises/math/calcul/proportionality/isTableProportional.js +7 -1
  10. package/lib/exercises/math/calcul/proportionality/isTableProportionalNonInteger.d.ts.map +1 -1
  11. package/lib/exercises/math/calcul/proportionality/isTableProportionalNonInteger.js +5 -1
  12. package/lib/exercises/math/calcul/proportionality/proportionalityTable.d.ts.map +1 -1
  13. package/lib/exercises/math/calcul/proportionality/proportionalityTable.js +5 -1
  14. package/lib/exercises/math/calcul/proportionality/proportionalityTableCoefficient.d.ts.map +1 -1
  15. package/lib/exercises/math/calcul/proportionality/proportionalityTableCoefficient.js +8 -2
  16. package/lib/exercises/math/calculLitteral/equation/index.d.ts +1 -1
  17. package/lib/exercises/math/calculLitteral/equation/index.d.ts.map +1 -1
  18. package/lib/exercises/math/calculLitteral/equation/index.js +1 -1
  19. package/lib/exercises/math/calculLitteral/equation/square/equationSimpleSquare.d.ts +10 -0
  20. package/lib/exercises/math/calculLitteral/equation/square/equationSimpleSquare.d.ts.map +1 -0
  21. package/lib/exercises/math/calculLitteral/equation/square/equationSimpleSquare.js +183 -0
  22. package/lib/exercises/math/calculLitteral/equation/square/equationSquareWithSteps.d.ts +10 -0
  23. package/lib/exercises/math/calculLitteral/equation/square/equationSquareWithSteps.d.ts.map +1 -0
  24. package/lib/exercises/math/calculLitteral/equation/square/equationSquareWithSteps.js +173 -0
  25. package/lib/exercises/math/calculLitteral/equation/square/index.d.ts +3 -0
  26. package/lib/exercises/math/calculLitteral/equation/square/index.d.ts.map +1 -0
  27. package/lib/exercises/math/calculLitteral/equation/square/index.js +2 -0
  28. package/lib/exercises/math/dataRepresentations/histogram/histogramIsSameData.d.ts.map +1 -1
  29. package/lib/exercises/math/dataRepresentations/histogram/histogramIsSameData.js +7 -0
  30. package/lib/exercises/math/dataRepresentations/tableReading.d.ts.map +1 -1
  31. package/lib/exercises/math/dataRepresentations/tableReading.js +7 -0
  32. package/lib/exercises/math/functions/affines/affineAdjustment.d.ts.map +1 -1
  33. package/lib/exercises/math/functions/affines/affineAdjustment.js +7 -1
  34. package/lib/exercises/math/functions/affines/affineAdjustmentComplete.d.ts.map +1 -1
  35. package/lib/exercises/math/functions/affines/affineAdjustmentComplete.js +7 -1
  36. package/lib/exercises/math/functions/affines/affineAdjustmentRsquared.d.ts.map +1 -1
  37. package/lib/exercises/math/functions/affines/affineAdjustmentRsquared.js +7 -1
  38. package/lib/exercises/math/functions/basics/inverseImageFunctionTable.d.ts.map +1 -1
  39. package/lib/exercises/math/functions/basics/inverseImageFunctionTable.js +7 -1
  40. package/lib/exercises/math/functions/basics/placePointsFromValueTable.d.ts.map +1 -1
  41. package/lib/exercises/math/functions/basics/placePointsFromValueTable.js +7 -0
  42. package/lib/exercises/math/functions/sqrt/squareRootCalculation.d.ts.map +1 -1
  43. package/lib/exercises/math/functions/sqrt/squareRootCalculation.js +4 -2
  44. package/lib/exercises/math/geometry/euclidian/homothetyFactorFromPoints.d.ts +15 -0
  45. package/lib/exercises/math/geometry/euclidian/homothetyFactorFromPoints.d.ts.map +1 -0
  46. package/lib/exercises/math/geometry/euclidian/homothetyFactorFromPoints.js +301 -0
  47. package/lib/exercises/math/geometry/euclidian/index.d.ts +7 -0
  48. package/lib/exercises/math/geometry/euclidian/index.d.ts.map +1 -1
  49. package/lib/exercises/math/geometry/euclidian/index.js +7 -0
  50. package/lib/exercises/math/geometry/euclidian/pinPointFromAxialOrCentralSymmetry.d.ts +21 -0
  51. package/lib/exercises/math/geometry/euclidian/pinPointFromAxialOrCentralSymmetry.d.ts.map +1 -0
  52. package/lib/exercises/math/geometry/euclidian/pinPointFromAxialOrCentralSymmetry.js +406 -0
  53. package/lib/exercises/math/geometry/euclidian/pinPointFromRotation.d.ts +18 -0
  54. package/lib/exercises/math/geometry/euclidian/pinPointFromRotation.d.ts.map +1 -0
  55. package/lib/exercises/math/geometry/euclidian/pinPointFromRotation.js +315 -0
  56. package/lib/exercises/math/geometry/euclidian/pinPointFromTranslation.d.ts +20 -0
  57. package/lib/exercises/math/geometry/euclidian/pinPointFromTranslation.d.ts.map +1 -0
  58. package/lib/exercises/math/geometry/euclidian/pinPointFromTranslation.js +314 -0
  59. package/lib/exercises/math/geometry/euclidian/pinSegmentFromRotation.d.ts +18 -0
  60. package/lib/exercises/math/geometry/euclidian/pinSegmentFromRotation.d.ts.map +1 -0
  61. package/lib/exercises/math/geometry/euclidian/pinSegmentFromRotation.js +387 -0
  62. package/lib/exercises/math/geometry/euclidian/recognizeAngleFromRotation.d.ts +18 -0
  63. package/lib/exercises/math/geometry/euclidian/recognizeAngleFromRotation.d.ts.map +1 -0
  64. package/lib/exercises/math/geometry/euclidian/recognizeAngleFromRotation.js +309 -0
  65. package/lib/exercises/math/geometry/euclidian/recognizeHomothetyCenter.d.ts +17 -0
  66. package/lib/exercises/math/geometry/euclidian/recognizeHomothetyCenter.d.ts.map +1 -0
  67. package/lib/exercises/math/geometry/euclidian/recognizeHomothetyCenter.js +301 -0
  68. package/lib/exercises/math/geometry/euclidianConstructions/buildPointFromAxialSymetry.d.ts.map +1 -1
  69. package/lib/exercises/math/geometry/euclidianConstructions/buildPointFromAxialSymetry.js +22 -8
  70. package/lib/exercises/math/geometry/euclidianConstructions/buildPointFromCentralSymmetry.d.ts +11 -0
  71. package/lib/exercises/math/geometry/euclidianConstructions/buildPointFromCentralSymmetry.d.ts.map +1 -0
  72. package/lib/exercises/math/geometry/euclidianConstructions/buildPointFromCentralSymmetry.js +169 -0
  73. package/lib/exercises/math/geometry/euclidianConstructions/index.d.ts +2 -0
  74. package/lib/exercises/math/geometry/euclidianConstructions/index.d.ts.map +1 -1
  75. package/lib/exercises/math/geometry/euclidianConstructions/index.js +2 -0
  76. package/lib/exercises/math/geometry/euclidianConstructions/placeHomothetyCenter.d.ts +16 -0
  77. package/lib/exercises/math/geometry/euclidianConstructions/placeHomothetyCenter.d.ts.map +1 -0
  78. package/lib/exercises/math/geometry/euclidianConstructions/placeHomothetyCenter.js +309 -0
  79. package/lib/exercises/math/probaStat/basicProbas/calculateProbaFromProbaLaw.d.ts.map +1 -1
  80. package/lib/exercises/math/probaStat/basicProbas/calculateProbaFromProbaLaw.js +7 -0
  81. package/lib/exercises/math/probaStat/basicProbas/getMissingProbabilityValue.d.ts.map +1 -1
  82. package/lib/exercises/math/probaStat/basicProbas/getMissingProbabilityValue.js +7 -0
  83. package/lib/exercises/math/probaStat/basicProbas/getMissingProbabilityValueMiddleSchool.d.ts +9 -0
  84. package/lib/exercises/math/probaStat/basicProbas/getMissingProbabilityValueMiddleSchool.d.ts.map +1 -0
  85. package/lib/exercises/math/probaStat/basicProbas/getMissingProbabilityValueMiddleSchool.js +120 -0
  86. package/lib/exercises/math/probaStat/basicProbas/index.d.ts +2 -0
  87. package/lib/exercises/math/probaStat/basicProbas/index.d.ts.map +1 -1
  88. package/lib/exercises/math/probaStat/basicProbas/index.js +2 -0
  89. package/lib/exercises/math/probaStat/basicProbas/pickEquiprobableTo.d.ts +12 -0
  90. package/lib/exercises/math/probaStat/basicProbas/pickEquiprobableTo.d.ts.map +1 -0
  91. package/lib/exercises/math/probaStat/basicProbas/pickEquiprobableTo.js +374 -0
  92. package/lib/exercises/math/probaStat/probaFromTableNoContext.d.ts.map +1 -1
  93. package/lib/exercises/math/probaStat/probaFromTableNoContext.js +7 -0
  94. package/lib/exercises/math/probaStat/probaFromTableWithContext.d.ts.map +1 -1
  95. package/lib/exercises/math/probaStat/probaFromTableWithContext.js +7 -0
  96. package/lib/exercises/math/probaStat/stats1var/averageWithClasses.d.ts +9 -0
  97. package/lib/exercises/math/probaStat/stats1var/averageWithClasses.d.ts.map +1 -0
  98. package/lib/exercises/math/probaStat/stats1var/averageWithClasses.js +140 -0
  99. package/lib/exercises/math/probaStat/stats1var/averageWithTable.d.ts.map +1 -1
  100. package/lib/exercises/math/probaStat/stats1var/averageWithTable.js +7 -1
  101. package/lib/exercises/math/probaStat/stats1var/averageWithTableWithContext.d.ts +8 -0
  102. package/lib/exercises/math/probaStat/stats1var/averageWithTableWithContext.d.ts.map +1 -0
  103. package/lib/exercises/math/probaStat/stats1var/averageWithTableWithContext.js +113 -0
  104. package/lib/exercises/math/probaStat/stats1var/calculateMeanFromFrequencies.d.ts.map +1 -1
  105. package/lib/exercises/math/probaStat/stats1var/calculateMeanFromFrequencies.js +7 -0
  106. package/lib/exercises/math/probaStat/stats1var/cumulativeSum.d.ts.map +1 -1
  107. package/lib/exercises/math/probaStat/stats1var/cumulativeSum.js +7 -0
  108. package/lib/exercises/math/probaStat/stats1var/etendueTable.d.ts.map +1 -1
  109. package/lib/exercises/math/probaStat/stats1var/etendueTable.js +7 -1
  110. package/lib/exercises/math/probaStat/stats1var/getQuartileProportionQuestion.d.ts.map +1 -1
  111. package/lib/exercises/math/probaStat/stats1var/getQuartileProportionQuestion.js +7 -0
  112. package/lib/exercises/math/probaStat/stats1var/index.d.ts +2 -0
  113. package/lib/exercises/math/probaStat/stats1var/index.d.ts.map +1 -1
  114. package/lib/exercises/math/probaStat/stats1var/index.js +2 -0
  115. package/lib/exercises/math/probaStat/stats1var/interquartilesTable.d.ts.map +1 -1
  116. package/lib/exercises/math/probaStat/stats1var/interquartilesTable.js +5 -1
  117. package/lib/exercises/math/probaStat/stats1var/marginalAndConditionalFrequency.d.ts.map +1 -1
  118. package/lib/exercises/math/probaStat/stats1var/marginalAndConditionalFrequency.js +7 -0
  119. package/lib/exercises/math/probaStat/stats1var/medianWithList.d.ts +2 -0
  120. package/lib/exercises/math/probaStat/stats1var/medianWithList.d.ts.map +1 -1
  121. package/lib/exercises/math/probaStat/stats1var/medianWithList.js +67 -14
  122. package/lib/exercises/math/probaStat/stats1var/medianWithTable.d.ts.map +1 -1
  123. package/lib/exercises/math/probaStat/stats1var/medianWithTable.js +7 -1
  124. package/lib/exercises/math/probaStat/stats1var/quartiles.d.ts.map +1 -1
  125. package/lib/exercises/math/probaStat/stats1var/quartiles.js +7 -1
  126. package/lib/exercises/math/probaStat/stats1var/standardDeviationTable.d.ts.map +1 -1
  127. package/lib/exercises/math/probaStat/stats1var/standardDeviationTable.js +5 -1
  128. package/lib/exercises/math/probaStat/stats1var/varianceTable.d.ts.map +1 -1
  129. package/lib/exercises/math/probaStat/stats1var/varianceTable.js +5 -1
  130. package/lib/exercises/math/probaStat/stats2var/averagePoint.d.ts.map +1 -1
  131. package/lib/exercises/math/probaStat/stats2var/averagePoint.js +7 -1
  132. package/lib/exercises/math/probaStat/twoStepExperiments/headsOrTailsTwiceOutcomes.d.ts +7 -0
  133. package/lib/exercises/math/probaStat/twoStepExperiments/headsOrTailsTwiceOutcomes.d.ts.map +1 -0
  134. package/lib/exercises/math/probaStat/twoStepExperiments/headsOrTailsTwiceOutcomes.js +171 -0
  135. package/lib/exercises/math/probaStat/twoStepExperiments/headsOrTailsTwiceProbas.d.ts +7 -0
  136. package/lib/exercises/math/probaStat/twoStepExperiments/headsOrTailsTwiceProbas.d.ts.map +1 -0
  137. package/lib/exercises/math/probaStat/twoStepExperiments/headsOrTailsTwiceProbas.js +155 -0
  138. package/lib/exercises/math/probaStat/twoStepExperiments/index.d.ts +3 -0
  139. package/lib/exercises/math/probaStat/twoStepExperiments/index.d.ts.map +1 -1
  140. package/lib/exercises/math/probaStat/twoStepExperiments/index.js +3 -0
  141. package/lib/exercises/math/probaStat/twoStepExperiments/numberPoolTwiceProbas.d.ts +7 -0
  142. package/lib/exercises/math/probaStat/twoStepExperiments/numberPoolTwiceProbas.d.ts.map +1 -0
  143. package/lib/exercises/math/probaStat/twoStepExperiments/numberPoolTwiceProbas.js +189 -0
  144. package/lib/exercises/math/scratch/index.d.ts +3 -0
  145. package/lib/exercises/math/scratch/index.d.ts.map +1 -1
  146. package/lib/exercises/math/scratch/index.js +3 -0
  147. package/lib/exercises/math/scratch/scratchListElemAtIndex.d.ts +13 -0
  148. package/lib/exercises/math/scratch/scratchListElemAtIndex.d.ts.map +1 -0
  149. package/lib/exercises/math/scratch/scratchListElemAtIndex.js +189 -0
  150. package/lib/exercises/math/scratch/scratchListElemAtIndex2.d.ts +23 -0
  151. package/lib/exercises/math/scratch/scratchListElemAtIndex2.d.ts.map +1 -0
  152. package/lib/exercises/math/scratch/scratchListElemAtIndex2.js +207 -0
  153. package/lib/exercises/math/scratch/scratchListFilter.d.ts +13 -0
  154. package/lib/exercises/math/scratch/scratchListFilter.d.ts.map +1 -0
  155. package/lib/exercises/math/scratch/scratchListFilter.js +397 -0
  156. package/lib/exercises/math/spaceGeometry/basis/findSpacePointOnRectangularPrism.d.ts +14 -0
  157. package/lib/exercises/math/spaceGeometry/basis/findSpacePointOnRectangularPrism.d.ts.map +1 -0
  158. package/lib/exercises/math/spaceGeometry/basis/findSpacePointOnRectangularPrism.js +347 -0
  159. package/lib/exercises/math/spaceGeometry/basis/index.d.ts +1 -0
  160. package/lib/exercises/math/spaceGeometry/basis/index.d.ts.map +1 -1
  161. package/lib/exercises/math/spaceGeometry/basis/index.js +1 -0
  162. package/lib/exercises/math/spaceGeometry/index.d.ts +2 -0
  163. package/lib/exercises/math/spaceGeometry/index.d.ts.map +1 -1
  164. package/lib/exercises/math/spaceGeometry/index.js +2 -0
  165. package/lib/exercises/math/spaceGeometry/sections/areaOfConeSection.js +3 -3
  166. package/lib/exercises/math/spaceGeometry/solids/index.d.ts +3 -0
  167. package/lib/exercises/math/spaceGeometry/solids/index.d.ts.map +1 -0
  168. package/lib/exercises/math/spaceGeometry/solids/index.js +2 -0
  169. package/lib/exercises/math/spaceGeometry/solids/recognizeSolidFrom3D.d.ts +15 -0
  170. package/lib/exercises/math/spaceGeometry/solids/recognizeSolidFrom3D.d.ts.map +1 -0
  171. package/lib/exercises/math/spaceGeometry/solids/recognizeSolidFrom3D.js +440 -0
  172. package/lib/exercises/math/spaceGeometry/solids/recognizeSolidFromSolidPattern.d.ts +11 -0
  173. package/lib/exercises/math/spaceGeometry/solids/recognizeSolidFromSolidPattern.d.ts.map +1 -0
  174. package/lib/exercises/math/spaceGeometry/solids/recognizeSolidFromSolidPattern.js +1089 -0
  175. package/lib/exercises/math/spaceGeometry/sphere/index.d.ts +3 -0
  176. package/lib/exercises/math/spaceGeometry/sphere/index.d.ts.map +1 -0
  177. package/lib/exercises/math/spaceGeometry/sphere/index.js +2 -0
  178. package/lib/exercises/math/spaceGeometry/sphere/pickIsPointInSphereOrBall.d.ts +9 -0
  179. package/lib/exercises/math/spaceGeometry/sphere/pickIsPointInSphereOrBall.d.ts.map +1 -0
  180. package/lib/exercises/math/spaceGeometry/sphere/pickIsPointInSphereOrBall.js +127 -0
  181. package/lib/exercises/math/spaceGeometry/sphere/sphereLatLonReading.d.ts +14 -0
  182. package/lib/exercises/math/spaceGeometry/sphere/sphereLatLonReading.d.ts.map +1 -0
  183. package/lib/exercises/math/spaceGeometry/sphere/sphereLatLonReading.js +390 -0
  184. package/lib/geogebra/geogebraConstructor.d.ts +2 -0
  185. package/lib/geogebra/geogebraConstructor.d.ts.map +1 -1
  186. package/lib/geogebra/geogebraConstructor.js +6 -0
  187. package/lib/index.d.ts +198 -6
  188. package/lib/index.d.ts.map +1 -1
  189. package/lib/math/geometry/point.d.ts +6 -0
  190. package/lib/math/geometry/point.d.ts.map +1 -1
  191. package/lib/math/geometry/point.js +28 -0
  192. package/lib/tree/nodes/equations/equalNode.d.ts +1 -1
  193. package/lib/tree/nodes/equations/equalNode.d.ts.map +1 -1
  194. package/lib/tree/nodes/equations/equalNode.js +0 -1
  195. package/lib/tree/utilities/nodeSimplifier.d.ts +1 -1
  196. package/lib/utils/arrays/arrayZip.d.ts +2 -0
  197. package/lib/utils/arrays/arrayZip.d.ts.map +1 -0
  198. package/lib/utils/arrays/arrayZip.js +12 -0
  199. package/package.json +1 -1
@@ -0,0 +1,189 @@
1
+ import { addValidProp, tryToAddWrongProp, } from "../../../exercises/exercise.js";
2
+ import { getDistinctQuestions } from "../../../exercises/utils/getDistinctQuestions.js";
3
+ import { randint } from "../../../math/utils/random/randint.js";
4
+ import { coinFlip } from "../../../utils/alea/coinFlip.js";
5
+ import { random, randomMany } from "../../../utils/alea/random.js";
6
+ import { shuffle } from "../../../utils/alea/shuffle.js";
7
+ import { mdTable } from "../../../utils/markdown/mdTable.js";
8
+ const getInstruction = (identifiers) => {
9
+ const { arrInsertion, indexAsked } = identifiers;
10
+ return `On considère le programme Scratch ci-dessous :
11
+
12
+ <svg id="scratch">
13
+ quand @greenFlag est cliqué
14
+ supprimer tous les éléments de la liste [l v]
15
+ ${arrInsertion.map(({ index, value }) => {
16
+ if (index === -1) {
17
+ return `ajouter [${value}] à [l v]`;
18
+ }
19
+ else {
20
+ return `insérer [${value}] en position [${index + 1}] de [l v]`;
21
+ }
22
+ }).join(`
23
+ `)}
24
+ dire (élément [${indexAsked + 1}] de [l v])
25
+ </svg>
26
+
27
+ Que va dire le lutin suite à l'exécution du programme ?`;
28
+ };
29
+ const getFunctionForScratchProgram = (identifiers) => {
30
+ const { arrInsertion, indexAsked } = identifiers;
31
+ return (_) => {
32
+ const outDict = {};
33
+ //init
34
+ const l = [];
35
+ outDict[0] = {
36
+ l: [...l],
37
+ };
38
+ //loop
39
+ let counter = 0;
40
+ arrInsertion.forEach(({ index, value }) => {
41
+ counter++;
42
+ if (index === -1 || index === l.length) {
43
+ l.push(value);
44
+ }
45
+ else {
46
+ l.splice(index, 0, value);
47
+ }
48
+ //store step dict
49
+ outDict[counter] = {
50
+ l: [...l],
51
+ };
52
+ });
53
+ //convenience: store last step in -1
54
+ outDict[-1] = outDict[Math.max(...Object.keys(outDict).map((k) => +k))];
55
+ outDict[-1].x = outDict[-1].l[indexAsked];
56
+ return outDict;
57
+ };
58
+ };
59
+ const getAnswer = (identifiers) => {
60
+ const { isUsingLetters } = identifiers;
61
+ const xRaw = getFunctionForScratchProgram(identifiers)(identifiers)[-1].x;
62
+ if (isUsingLetters) {
63
+ return xRaw;
64
+ }
65
+ else {
66
+ return xRaw.frenchify();
67
+ }
68
+ };
69
+ const getHint = () => {
70
+ return `La liste $l$ change au cours de l'exécution du programme.
71
+
72
+ À chaque instruction, détermine comment la liste évolue.
73
+
74
+ Insérer un élement à une position décale l'élément existant à cette position et tous les suivants, pour laisser la place au nouvel arrivant.
75
+
76
+ L'état final de $l$ te permettra de répondre à la question posée.`;
77
+ };
78
+ const getCorrection = (identifiers) => {
79
+ const { arrInsertion, indexAsked } = identifiers;
80
+ const dictSteps = getFunctionForScratchProgram(identifiers)(identifiers);
81
+ return `Voici l'évolution de la liste $l$ au fil des instructions.
82
+
83
+ ${mdTable([
84
+ ["\\text{Initialement: vide}", "\\text{}", "\\text{}", "\\text{}"],
85
+ ...arrInsertion.map(({ index, value }, i) => {
86
+ const l = dictSteps[i + 1].l;
87
+ return [
88
+ index === -1
89
+ ? `\\text{Après "ajouter ${value} à l"}`
90
+ : `\\text{Après "insérer ${value} en pos. ${index + 1}"}`,
91
+ l.length > 0 ? `${l[0]}` : "\\text{}",
92
+ l.length > 1 ? `${l[1]}` : "\\text{}",
93
+ l.length > 2 ? `${l[2]}` : "\\text{}",
94
+ ];
95
+ }),
96
+ ], true)}
97
+
98
+ À la fin de l'exécution du programme, $l$ vaut donc $[${dictSteps[-1].l.join(";")}]$.
99
+
100
+ L'élément à la position $${indexAsked + 1}$ de $l$ est $${dictSteps[-1].x}$.`;
101
+ };
102
+ const getPropositions = (_, { answer, ...identifiers }) => {
103
+ const { isUsingLetters } = identifiers;
104
+ const propositions = [];
105
+ if (isUsingLetters) {
106
+ const valuesPool = ["A", "B", "C"];
107
+ valuesPool.forEach((str) => {
108
+ (str === answer ? addValidProp : tryToAddWrongProp)(propositions, str);
109
+ });
110
+ }
111
+ else {
112
+ const valuesPool = [1, 2, 3];
113
+ valuesPool.forEach((v) => {
114
+ const tex = v.frenchify();
115
+ (tex === answer ? addValidProp : tryToAddWrongProp)(propositions, tex);
116
+ });
117
+ }
118
+ return propositions;
119
+ };
120
+ const getKeys = ({ isUsingLetters }) => {
121
+ return isUsingLetters ? ["A", "B", "C"] : [];
122
+ };
123
+ const isAnswerValid = (ans, { answer }) => {
124
+ return ans === answer;
125
+ };
126
+ const getScratchListElemAtIndexQuestion = () => {
127
+ const shuffleArray = coinFlip()
128
+ ? shuffle([0, 1, 2])
129
+ : shuffle([...randomMany([0, 1, 2], 2), random([0, 1, 2])]);
130
+ const isUsingLetters = coinFlip();
131
+ let arrInsertion = [];
132
+ if (isUsingLetters) {
133
+ const valuesPool = ["A", "B", "C"];
134
+ const values = shuffleArray.map((i) => valuesPool[i]);
135
+ arrInsertion = values.map((v, i) => {
136
+ return {
137
+ index: coinFlip() ? -1 : randint(0, i + 1),
138
+ value: v,
139
+ };
140
+ });
141
+ }
142
+ else {
143
+ const valuesPool = [1, 2, 3];
144
+ const values = shuffleArray.map((i) => valuesPool[i]);
145
+ arrInsertion = values.map((v, i) => {
146
+ return {
147
+ index: coinFlip() ? -1 : randint(0, i + 1),
148
+ value: v,
149
+ };
150
+ });
151
+ }
152
+ const indexRawLast = arrInsertion[arrInsertion.length - 1].index;
153
+ const indexAsked = randint(0, arrInsertion.length, indexRawLast !== -1 ? [indexRawLast] : []);
154
+ const identifiers = {
155
+ isUsingLetters,
156
+ arrInsertion,
157
+ indexAsked,
158
+ };
159
+ return getQuestionFromIdentifiers(identifiers);
160
+ };
161
+ const getQuestionFromIdentifiers = (identifiers) => {
162
+ return {
163
+ answer: getAnswer(identifiers),
164
+ instruction: getInstruction(identifiers),
165
+ keys: getKeys(identifiers),
166
+ answerFormat: "tex",
167
+ identifiers,
168
+ hint: getHint(identifiers),
169
+ correction: getCorrection(identifiers),
170
+ };
171
+ };
172
+ export const scratchListElemAtIndex = {
173
+ id: "scratchListElemAtIndex",
174
+ connector: "=",
175
+ label: "Donner un élément d'une liste en Scratch",
176
+ isSingleStep: true,
177
+ generator: (nb, opts) => getDistinctQuestions(() => getScratchListElemAtIndexQuestion(opts), nb),
178
+ qcmTimer: 60,
179
+ freeTimer: 60,
180
+ getPropositions,
181
+ isAnswerValid,
182
+ subject: "Mathématiques",
183
+ getInstruction,
184
+ getHint,
185
+ getCorrection,
186
+ getAnswer,
187
+ getQuestionFromIdentifiers,
188
+ hasHintAndCorrection: true,
189
+ };
@@ -0,0 +1,23 @@
1
+ import { Exercise } from "../../../exercises/exercise.js";
2
+ type Insertion<T> = {
3
+ index: number;
4
+ value: T;
5
+ };
6
+ type Injection<T> = {
7
+ index: number;
8
+ value: T;
9
+ };
10
+ type Instruction<T> = ({
11
+ type: "insertion";
12
+ } & Insertion<T>) | ({
13
+ type: "injection";
14
+ } & Injection<T>);
15
+ type Identifiers = {
16
+ lStart: number[] | string[];
17
+ isUsingLetters: boolean;
18
+ arrInstruction: Instruction<number>[] | Instruction<string>[];
19
+ indexAsked: number;
20
+ };
21
+ export declare const scratchListElemAtIndex2: Exercise<Identifiers>;
22
+ export {};
23
+ //# sourceMappingURL=scratchListElemAtIndex2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scratchListElemAtIndex2.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/scratch/scratchListElemAtIndex2.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAWT,MAAM,6BAA6B,CAAC;AAQrC,KAAK,SAAS,CAAC,CAAC,IAAI;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,CAAC,CAAC;CACV,CAAC;AAEF,KAAK,SAAS,CAAC,CAAC,IAAI;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,CAAC,CAAC;CACV,CAAC;AAEF,KAAK,WAAW,CAAC,CAAC,IACd,CAAC;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,GACtC,CAAC;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;AAE3C,KAAK,WAAW,GAAG;IACjB,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC;IAC5B,cAAc,EAAE,OAAO,CAAC;IACxB,cAAc,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,GAAG,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC;IAC9D,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AA4OF,eAAO,MAAM,uBAAuB,EAAE,QAAQ,CAAC,WAAW,CAkBzD,CAAC"}
@@ -0,0 +1,207 @@
1
+ import { addValidProp, tryToAddWrongProp, } from "../../../exercises/exercise.js";
2
+ import { getDistinctQuestions } from "../../../exercises/utils/getDistinctQuestions.js";
3
+ import { randint } from "../../../math/utils/random/randint.js";
4
+ import { coinFlip } from "../../../utils/alea/coinFlip.js";
5
+ import { random, randomMany } from "../../../utils/alea/random.js";
6
+ import { shuffle } from "../../../utils/alea/shuffle.js";
7
+ import { mdTable } from "../../../utils/markdown/mdTable.js";
8
+ const getInstruction = (identifiers) => {
9
+ const { lStart, arrInstruction, indexAsked } = identifiers;
10
+ return `On considère le programme Scratch ci-dessous :
11
+
12
+ <svg id="scratch">
13
+ quand @greenFlag est cliqué
14
+ ${arrInstruction.map(({ type, index, value }) => {
15
+ if (type === "insertion") {
16
+ if (index === -1) {
17
+ return `ajouter [${value}] à [l v]`;
18
+ }
19
+ else {
20
+ return `insérer [${value}] en position [${index + 1}] de [l v]`;
21
+ }
22
+ }
23
+ else {
24
+ return `remplacer l'élément [${index + 1}] de la liste [l v] par [${value}]`;
25
+ }
26
+ }).join(`
27
+ `)}
28
+ dire (élément [${indexAsked + 1}] de [l v])
29
+ </svg>
30
+
31
+ Si la liste $l$ vaut initialement $[${lStart.join(";")}]$, que va dire le lutin suite à l'exécution du programme ?`;
32
+ };
33
+ const getFunctionForScratchProgram = (identifiers) => {
34
+ const { lStart, arrInstruction, indexAsked } = identifiers;
35
+ return (_) => {
36
+ const outDict = {};
37
+ //init
38
+ const l = [...lStart];
39
+ outDict[0] = {
40
+ l: [...l],
41
+ };
42
+ //loop
43
+ let counter = 0;
44
+ arrInstruction.forEach(({ type, index, value }) => {
45
+ counter++;
46
+ if (type === "insertion") {
47
+ if (index === -1 || index === l.length) {
48
+ l.push(value);
49
+ }
50
+ else {
51
+ l.splice(index, 0, value);
52
+ }
53
+ }
54
+ else {
55
+ l[index] = value;
56
+ }
57
+ //store step dict
58
+ outDict[counter] = {
59
+ l: [...l],
60
+ };
61
+ });
62
+ //convenience: store last step in -1
63
+ outDict[-1] = outDict[Math.max(...Object.keys(outDict).map((k) => +k))];
64
+ outDict[-1].x = outDict[-1].l[indexAsked];
65
+ return outDict;
66
+ };
67
+ };
68
+ const getAnswer = (identifiers) => {
69
+ const { isUsingLetters } = identifiers;
70
+ const xRaw = getFunctionForScratchProgram(identifiers)(identifiers)[-1].x;
71
+ if (isUsingLetters) {
72
+ return xRaw;
73
+ }
74
+ else {
75
+ return xRaw.frenchify();
76
+ }
77
+ };
78
+ const getHint = () => {
79
+ return `La liste $l$ change au cours de l'exécution du programme.
80
+
81
+ À chaque instruction, détermine comment la liste évolue.
82
+
83
+ Insérer un élement à une position décale l'élément existant à cette position et tous les suivants, pour laisser la place au nouvel arrivant.
84
+
85
+ Remplacer un élément de la liste écrase l'ancien élément avec le nouveau.
86
+
87
+ L'état final de $l$ te permettra de répondre à la question posée.`;
88
+ };
89
+ const getCorrection = (identifiers) => {
90
+ const { arrInstruction, indexAsked } = identifiers;
91
+ const dictSteps = getFunctionForScratchProgram(identifiers)(identifiers);
92
+ const maxLength = dictSteps[-1].l.length;
93
+ return `Voici l'évolution de la liste $l$ au fil des instructions.
94
+
95
+ ${mdTable([
96
+ (() => {
97
+ const l = dictSteps[0].l;
98
+ return [
99
+ "\\text{Initialement}",
100
+ ...[...Array(maxLength).keys()].map((i) => l.length > i ? `${l[i]}` : "\\text{}"),
101
+ ];
102
+ })(),
103
+ ...arrInstruction.map(({ type, index, value }, i) => {
104
+ const l = dictSteps[i + 1].l;
105
+ return [
106
+ type === "insertion"
107
+ ? index === -1
108
+ ? `\\text{Après "ajouter ${value} à l"}`
109
+ : `\\text{Après "insérer ${value} en pos. ${index + 1}"}`
110
+ : `\\text{Après "rempl. l'élém. ${index + 1} par ${value}"}`,
111
+ ...[...Array(maxLength).keys()].map((i) => l.length > i ? `${l[i]}` : "\\text{}"),
112
+ ];
113
+ }),
114
+ ], true)}
115
+
116
+ À la fin de l'exécution du programme, $l$ vaut donc $[${dictSteps[-1].l.join(";")}]$.
117
+
118
+ L'élément à la position $${indexAsked + 1}$ de $l$ est $${dictSteps[-1].x}$.`;
119
+ };
120
+ const getPropositions = (_, { answer, ...identifiers }) => {
121
+ const { isUsingLetters } = identifiers;
122
+ const propositions = [];
123
+ if (isUsingLetters) {
124
+ const valuesPool = ["A", "B", "C"];
125
+ valuesPool.forEach((str) => {
126
+ (str === answer ? addValidProp : tryToAddWrongProp)(propositions, str);
127
+ });
128
+ }
129
+ else {
130
+ const valuesPool = [1, 2, 3];
131
+ valuesPool.forEach((v) => {
132
+ const tex = v.frenchify();
133
+ (tex === answer ? addValidProp : tryToAddWrongProp)(propositions, tex);
134
+ });
135
+ }
136
+ return propositions;
137
+ };
138
+ const getScratchListElemAtIndex2Question = () => {
139
+ const shuffleArray = coinFlip()
140
+ ? shuffle([0, 1, 2])
141
+ : shuffle([...randomMany([0, 1, 2], 2), random([0, 1, 2])]);
142
+ const isUsingLetters = coinFlip();
143
+ const letterPool = ["A", "B", "C"];
144
+ const numberPool = [1, 2, 3];
145
+ const lengthLStart = randint(1, 4);
146
+ const lStart = [...Array(lengthLStart).keys()].map(() => isUsingLetters ? random(letterPool) : random(numberPool));
147
+ const values = shuffleArray.map((i) => (isUsingLetters ? letterPool : numberPool)[i]);
148
+ const arrInstruction = values.map((v, i) => {
149
+ const type = coinFlip() ? "insertion" : "injection";
150
+ return {
151
+ type,
152
+ index: type === "insertion"
153
+ ? coinFlip()
154
+ ? -1
155
+ : randint(0, i + 1)
156
+ : randint(0, i),
157
+ value: v,
158
+ };
159
+ });
160
+ const indexRawLast = arrInstruction[arrInstruction.length - 1].index;
161
+ const indexMax = (() => {
162
+ const identifiersProbe = {
163
+ lStart,
164
+ isUsingLetters,
165
+ arrInstruction,
166
+ indexAsked: 0,
167
+ };
168
+ const dictSteps = getFunctionForScratchProgram(identifiersProbe)(identifiersProbe);
169
+ return dictSteps[-1].l.length;
170
+ })();
171
+ const indexAsked = randint(0, indexMax, indexMax !== 1 && indexRawLast !== -1 ? [indexRawLast] : []);
172
+ const identifiers = {
173
+ lStart,
174
+ isUsingLetters,
175
+ arrInstruction,
176
+ indexAsked,
177
+ };
178
+ return getQuestionFromIdentifiers(identifiers);
179
+ };
180
+ const getQuestionFromIdentifiers = (identifiers) => {
181
+ return {
182
+ answer: getAnswer(identifiers),
183
+ instruction: getInstruction(identifiers),
184
+ answerFormat: "tex",
185
+ identifiers,
186
+ hint: getHint(identifiers),
187
+ correction: getCorrection(identifiers),
188
+ };
189
+ };
190
+ export const scratchListElemAtIndex2 = {
191
+ id: "scratchListElemAtIndex2",
192
+ connector: "=",
193
+ label: "Donner un élément d'une liste en Scratch ($2$)",
194
+ isSingleStep: true,
195
+ generator: (nb, opts) => getDistinctQuestions(() => getScratchListElemAtIndex2Question(opts), nb),
196
+ qcmTimer: 60,
197
+ freeTimer: 60,
198
+ getPropositions,
199
+ subject: "Mathématiques",
200
+ getInstruction,
201
+ getHint,
202
+ getCorrection,
203
+ getAnswer,
204
+ getQuestionFromIdentifiers,
205
+ hasHintAndCorrection: true,
206
+ answerType: "QCU",
207
+ };
@@ -0,0 +1,13 @@
1
+ import { Exercise } from "../../../exercises/exercise.js";
2
+ type Identifiers = {
3
+ l1Start: number[];
4
+ randCounter: number;
5
+ randX: number;
6
+ randCondition: number;
7
+ isGreaterCond: boolean;
8
+ k?: number;
9
+ randListAdd: number;
10
+ };
11
+ export declare const scratchListFilter: Exercise<Identifiers>;
12
+ export {};
13
+ //# sourceMappingURL=scratchListFilter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scratchListFilter.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/scratch/scratchListFilter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAYT,MAAM,6BAA6B,CAAC;AAOrC,KAAK,WAAW,GAAG;IACjB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,OAAO,CAAC;IACvB,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAmdF,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,WAAW,CAkBnD,CAAC"}