math-exercises 3.0.149 → 3.0.151

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 (184) hide show
  1. package/lib/exercises/math/calcul/arithmetics/primeNumbersAffirmations.js +1 -1
  2. package/lib/exercises/math/calculLitteral/equation/equa1.d.ts +4 -1
  3. package/lib/exercises/math/calculLitteral/equation/equa1.d.ts.map +1 -1
  4. package/lib/exercises/math/calculLitteral/equation/equa1.js +27 -7
  5. package/lib/exercises/math/calculLitteral/equation/equa2.d.ts +1 -0
  6. package/lib/exercises/math/calculLitteral/equation/equa2.d.ts.map +1 -1
  7. package/lib/exercises/math/calculLitteral/equation/equa2.js +18 -1
  8. package/lib/exercises/math/calculLitteral/equation/equa3.d.ts +4 -1
  9. package/lib/exercises/math/calculLitteral/equation/equa3.d.ts.map +1 -1
  10. package/lib/exercises/math/calculLitteral/equation/equa3.js +26 -6
  11. package/lib/exercises/math/calculLitteral/equation/equa4.d.ts +4 -1
  12. package/lib/exercises/math/calculLitteral/equation/equa4.d.ts.map +1 -1
  13. package/lib/exercises/math/calculLitteral/equation/equa4.js +27 -7
  14. package/lib/exercises/math/calculLitteral/equation/firstDegree/equa1.d.ts +14 -0
  15. package/lib/exercises/math/calculLitteral/equation/firstDegree/equa1.d.ts.map +1 -0
  16. package/lib/exercises/math/calculLitteral/equation/firstDegree/equa1.js +129 -0
  17. package/lib/exercises/math/calculLitteral/equation/firstDegree/equa2.d.ts +18 -0
  18. package/lib/exercises/math/calculLitteral/equation/firstDegree/equa2.d.ts.map +1 -0
  19. package/lib/exercises/math/calculLitteral/equation/firstDegree/equa2.js +167 -0
  20. package/lib/exercises/math/calculLitteral/equation/firstDegree/equa3.d.ts +15 -0
  21. package/lib/exercises/math/calculLitteral/equation/firstDegree/equa3.d.ts.map +1 -0
  22. package/lib/exercises/math/calculLitteral/equation/firstDegree/equa3.js +129 -0
  23. package/lib/exercises/math/calculLitteral/equation/firstDegree/equa4.d.ts +16 -0
  24. package/lib/exercises/math/calculLitteral/equation/firstDegree/equa4.d.ts.map +1 -0
  25. package/lib/exercises/math/calculLitteral/equation/firstDegree/equa4.js +124 -0
  26. package/lib/exercises/math/calculLitteral/equation/firstDegree/firstDegreeEquationIntType1.d.ts +9 -0
  27. package/lib/exercises/math/calculLitteral/equation/firstDegree/firstDegreeEquationIntType1.d.ts.map +1 -0
  28. package/lib/exercises/math/calculLitteral/equation/firstDegree/firstDegreeEquationIntType1.js +107 -0
  29. package/lib/exercises/math/calculLitteral/equation/firstDegree/firstDegreeEquationIntType2.d.ts +10 -0
  30. package/lib/exercises/math/calculLitteral/equation/firstDegree/firstDegreeEquationIntType2.d.ts.map +1 -0
  31. package/lib/exercises/math/calculLitteral/equation/firstDegree/firstDegreeEquationIntType2.js +108 -0
  32. package/lib/exercises/math/calculLitteral/equation/firstDegree/firstDegreeEquationIntType3.d.ts +11 -0
  33. package/lib/exercises/math/calculLitteral/equation/firstDegree/firstDegreeEquationIntType3.d.ts.map +1 -0
  34. package/lib/exercises/math/calculLitteral/equation/firstDegree/firstDegreeEquationIntType3.js +104 -0
  35. package/lib/exercises/math/calculLitteral/equation/firstDegree/index.d.ts +8 -0
  36. package/lib/exercises/math/calculLitteral/equation/firstDegree/index.d.ts.map +1 -0
  37. package/lib/exercises/math/calculLitteral/equation/firstDegree/index.js +7 -0
  38. package/lib/exercises/math/calculLitteral/equation/index.d.ts +1 -7
  39. package/lib/exercises/math/calculLitteral/equation/index.d.ts.map +1 -1
  40. package/lib/exercises/math/calculLitteral/equation/index.js +1 -7
  41. package/lib/exercises/math/dataRepresentations/histogram/etendueHistogram.d.ts +8 -0
  42. package/lib/exercises/math/dataRepresentations/histogram/etendueHistogram.d.ts.map +1 -0
  43. package/lib/exercises/math/dataRepresentations/histogram/etendueHistogram.js +175 -0
  44. package/lib/exercises/math/dataRepresentations/histogram/histogramCommenting.d.ts +9 -0
  45. package/lib/exercises/math/dataRepresentations/histogram/histogramCommenting.d.ts.map +1 -0
  46. package/lib/exercises/math/dataRepresentations/histogram/histogramCommenting.js +250 -0
  47. package/lib/exercises/math/dataRepresentations/histogram/histogramFillDataTableFromHistogramData.d.ts +9 -0
  48. package/lib/exercises/math/dataRepresentations/histogram/histogramFillDataTableFromHistogramData.d.ts.map +1 -0
  49. package/lib/exercises/math/dataRepresentations/histogram/histogramFillDataTableFromHistogramData.js +173 -0
  50. package/lib/exercises/math/dataRepresentations/histogram/histogramIsSameData.d.ts +14 -0
  51. package/lib/exercises/math/dataRepresentations/histogram/histogramIsSameData.d.ts.map +1 -0
  52. package/lib/exercises/math/dataRepresentations/histogram/histogramIsSameData.js +232 -0
  53. package/lib/exercises/math/dataRepresentations/histogram/histogramReading.d.ts +9 -0
  54. package/lib/exercises/math/dataRepresentations/histogram/histogramReading.d.ts.map +1 -0
  55. package/lib/exercises/math/dataRepresentations/histogram/histogramReading.js +163 -0
  56. package/lib/exercises/math/dataRepresentations/histogram/index.d.ts +6 -0
  57. package/lib/exercises/math/dataRepresentations/histogram/index.d.ts.map +1 -0
  58. package/lib/exercises/math/dataRepresentations/histogram/index.js +5 -0
  59. package/lib/exercises/math/dataRepresentations/index.d.ts +1 -1
  60. package/lib/exercises/math/dataRepresentations/index.d.ts.map +1 -1
  61. package/lib/exercises/math/dataRepresentations/index.js +1 -1
  62. package/lib/exercises/math/functions/affines/leadingCoeffAndOriginOrdinate.d.ts +4 -1
  63. package/lib/exercises/math/functions/affines/leadingCoeffAndOriginOrdinate.d.ts.map +1 -1
  64. package/lib/exercises/math/functions/affines/leadingCoeffAndOriginOrdinate.js +19 -4
  65. package/lib/exercises/math/functions/affines/leadingCoefficient.d.ts +1 -0
  66. package/lib/exercises/math/functions/affines/leadingCoefficient.d.ts.map +1 -1
  67. package/lib/exercises/math/functions/affines/leadingCoefficient.js +13 -1
  68. package/lib/exercises/math/functions/affines/recognizeAffineGraph.d.ts +4 -1
  69. package/lib/exercises/math/functions/affines/recognizeAffineGraph.d.ts.map +1 -1
  70. package/lib/exercises/math/functions/affines/recognizeAffineGraph.js +19 -4
  71. package/lib/exercises/math/geometry/euclidian/pythagoreOrThales.d.ts +4 -1
  72. package/lib/exercises/math/geometry/euclidian/pythagoreOrThales.d.ts.map +1 -1
  73. package/lib/exercises/math/geometry/euclidian/pythagoreOrThales.js +18 -3
  74. package/lib/exercises/math/geometry/triangles/index.d.ts +1 -0
  75. package/lib/exercises/math/geometry/triangles/index.d.ts.map +1 -1
  76. package/lib/exercises/math/geometry/triangles/index.js +1 -0
  77. package/lib/exercises/math/geometry/triangles/similar/index.d.ts +4 -0
  78. package/lib/exercises/math/geometry/triangles/similar/index.d.ts.map +1 -0
  79. package/lib/exercises/math/geometry/triangles/similar/index.js +3 -0
  80. package/lib/exercises/math/geometry/triangles/similar/isSimilarTrianglesWithAngles.d.ts +10 -0
  81. package/lib/exercises/math/geometry/triangles/similar/isSimilarTrianglesWithAngles.d.ts.map +1 -0
  82. package/lib/exercises/math/geometry/triangles/similar/isSimilarTrianglesWithAngles.js +122 -0
  83. package/lib/exercises/math/geometry/triangles/similar/isSimilarTrianglesWrtSideLengths.d.ts +15 -0
  84. package/lib/exercises/math/geometry/triangles/similar/isSimilarTrianglesWrtSideLengths.d.ts.map +1 -0
  85. package/lib/exercises/math/geometry/triangles/similar/isSimilarTrianglesWrtSideLengths.js +351 -0
  86. package/lib/exercises/math/geometry/triangles/similar/placeSegmentsOfSimilarTriangle.d.ts +11 -0
  87. package/lib/exercises/math/geometry/triangles/similar/placeSegmentsOfSimilarTriangle.d.ts.map +1 -0
  88. package/lib/exercises/math/geometry/triangles/similar/placeSegmentsOfSimilarTriangle.js +311 -0
  89. package/lib/exercises/math/probaStat/basicProbas/calculateProbaFromProbaLaw.d.ts +10 -0
  90. package/lib/exercises/math/probaStat/basicProbas/calculateProbaFromProbaLaw.d.ts.map +1 -0
  91. package/lib/exercises/math/probaStat/basicProbas/calculateProbaFromProbaLaw.js +128 -0
  92. package/lib/exercises/math/probaStat/basicProbas/findEffectifFromProba.d.ts +9 -0
  93. package/lib/exercises/math/probaStat/basicProbas/findEffectifFromProba.d.ts.map +1 -0
  94. package/lib/exercises/math/probaStat/basicProbas/findEffectifFromProba.js +109 -0
  95. package/lib/exercises/math/probaStat/basicProbas/index.d.ts +2 -0
  96. package/lib/exercises/math/probaStat/basicProbas/index.d.ts.map +1 -1
  97. package/lib/exercises/math/probaStat/basicProbas/index.js +2 -0
  98. package/lib/exercises/math/scratch/index.d.ts +13 -0
  99. package/lib/exercises/math/scratch/index.d.ts.map +1 -1
  100. package/lib/exercises/math/scratch/index.js +14 -0
  101. package/lib/exercises/math/scratch/scratchCond1.d.ts +25 -0
  102. package/lib/exercises/math/scratch/scratchCond1.d.ts.map +1 -0
  103. package/lib/exercises/math/scratch/scratchCond1.js +290 -0
  104. package/lib/exercises/math/scratch/scratchFunction1.d.ts +9 -0
  105. package/lib/exercises/math/scratch/scratchFunction1.d.ts.map +1 -0
  106. package/lib/exercises/math/scratch/scratchFunction1.js +199 -0
  107. package/lib/exercises/math/scratch/scratchLoop1.d.ts +10 -0
  108. package/lib/exercises/math/scratch/scratchLoop1.d.ts.map +1 -0
  109. package/lib/exercises/math/scratch/scratchLoop1.js +207 -0
  110. package/lib/exercises/math/scratch/scratchLoopCond1.d.ts +12 -0
  111. package/lib/exercises/math/scratch/scratchLoopCond1.d.ts.map +1 -0
  112. package/lib/exercises/math/scratch/scratchLoopCond1.js +236 -0
  113. package/lib/exercises/math/scratch/scratchLoopCond2.d.ts +14 -0
  114. package/lib/exercises/math/scratch/scratchLoopCond2.d.ts.map +1 -0
  115. package/lib/exercises/math/scratch/scratchLoopCond2.js +219 -0
  116. package/lib/exercises/math/scratch/scratchOperations1.d.ts +8 -0
  117. package/lib/exercises/math/scratch/scratchOperations1.d.ts.map +1 -0
  118. package/lib/exercises/math/scratch/scratchOperations1.js +245 -0
  119. package/lib/exercises/math/scratch/scratchOperations2.d.ts +10 -0
  120. package/lib/exercises/math/scratch/scratchOperations2.d.ts.map +1 -0
  121. package/lib/exercises/math/scratch/scratchOperations2.js +324 -0
  122. package/lib/exercises/math/scratch/scratchPrintXY.d.ts +9 -0
  123. package/lib/exercises/math/scratch/scratchPrintXY.d.ts.map +1 -0
  124. package/lib/exercises/math/scratch/scratchPrintXY.js +194 -0
  125. package/lib/exercises/math/scratch/scratchStringLoop.d.ts +10 -0
  126. package/lib/exercises/math/scratch/scratchStringLoop.d.ts.map +1 -0
  127. package/lib/exercises/math/scratch/scratchStringLoop.js +192 -0
  128. package/lib/exercises/math/scratch/scratchStringLoopCond.d.ts +12 -0
  129. package/lib/exercises/math/scratch/scratchStringLoopCond.d.ts.map +1 -0
  130. package/lib/exercises/math/scratch/scratchStringLoopCond.js +270 -0
  131. package/lib/exercises/math/scratch/scratchStringLoopCond2.d.ts +12 -0
  132. package/lib/exercises/math/scratch/scratchStringLoopCond2.d.ts.map +1 -0
  133. package/lib/exercises/math/scratch/scratchStringLoopCond2.js +273 -0
  134. package/lib/exercises/math/scratch/scratchStringLoopCond3.d.ts +12 -0
  135. package/lib/exercises/math/scratch/scratchStringLoopCond3.d.ts.map +1 -0
  136. package/lib/exercises/math/scratch/scratchStringLoopCond3.js +275 -0
  137. package/lib/exercises/math/scratch/scratchSwapUsingTmp.d.ts +10 -0
  138. package/lib/exercises/math/scratch/scratchSwapUsingTmp.d.ts.map +1 -0
  139. package/lib/exercises/math/scratch/scratchSwapUsingTmp.js +199 -0
  140. package/lib/exercises/math/scratch/scratchVarWaterfall.d.ts +10 -0
  141. package/lib/exercises/math/scratch/scratchVarWaterfall.d.ts.map +1 -0
  142. package/lib/exercises/math/scratch/scratchVarWaterfall.js +371 -0
  143. package/lib/exercises/math/spaceGeometry/index.d.ts +1 -0
  144. package/lib/exercises/math/spaceGeometry/index.d.ts.map +1 -1
  145. package/lib/exercises/math/spaceGeometry/index.js +1 -0
  146. package/lib/exercises/math/spaceGeometry/sections/areaOfConeSection.d.ts +14 -0
  147. package/lib/exercises/math/spaceGeometry/sections/areaOfConeSection.d.ts.map +1 -0
  148. package/lib/exercises/math/spaceGeometry/sections/areaOfConeSection.js +439 -0
  149. package/lib/exercises/math/spaceGeometry/sections/areaOfCylinderSection.d.ts +14 -0
  150. package/lib/exercises/math/spaceGeometry/sections/areaOfCylinderSection.d.ts.map +1 -0
  151. package/lib/exercises/math/spaceGeometry/sections/areaOfCylinderSection.js +548 -0
  152. package/lib/exercises/math/spaceGeometry/sections/areaOfRectangularPrismSection.d.ts +11 -0
  153. package/lib/exercises/math/spaceGeometry/sections/areaOfRectangularPrismSection.d.ts.map +1 -0
  154. package/lib/exercises/math/spaceGeometry/sections/areaOfRectangularPrismSection.js +360 -0
  155. package/lib/exercises/math/spaceGeometry/sections/areaOfSphereSection.d.ts +9 -0
  156. package/lib/exercises/math/spaceGeometry/sections/areaOfSphereSection.d.ts.map +1 -0
  157. package/lib/exercises/math/spaceGeometry/sections/areaOfSphereSection.js +272 -0
  158. package/lib/exercises/math/spaceGeometry/sections/index.d.ts +9 -0
  159. package/lib/exercises/math/spaceGeometry/sections/index.d.ts.map +1 -0
  160. package/lib/exercises/math/spaceGeometry/sections/index.js +8 -0
  161. package/lib/exercises/math/spaceGeometry/sections/recognizeSectionsOfCone.d.ts +11 -0
  162. package/lib/exercises/math/spaceGeometry/sections/recognizeSectionsOfCone.d.ts.map +1 -0
  163. package/lib/exercises/math/spaceGeometry/sections/recognizeSectionsOfCone.js +266 -0
  164. package/lib/exercises/math/spaceGeometry/sections/recognizeSectionsOfCylinder.d.ts +11 -0
  165. package/lib/exercises/math/spaceGeometry/sections/recognizeSectionsOfCylinder.d.ts.map +1 -0
  166. package/lib/exercises/math/spaceGeometry/sections/recognizeSectionsOfCylinder.js +236 -0
  167. package/lib/exercises/math/spaceGeometry/sections/recognizeSectionsOfRectangularPrism.d.ts +7 -0
  168. package/lib/exercises/math/spaceGeometry/sections/recognizeSectionsOfRectangularPrism.d.ts.map +1 -0
  169. package/lib/exercises/math/spaceGeometry/sections/recognizeSectionsOfRectangularPrism.js +92 -0
  170. package/lib/exercises/math/spaceGeometry/sections/recognizeSectionsOfSphereOrBall.d.ts +9 -0
  171. package/lib/exercises/math/spaceGeometry/sections/recognizeSectionsOfSphereOrBall.d.ts.map +1 -0
  172. package/lib/exercises/math/spaceGeometry/sections/recognizeSectionsOfSphereOrBall.js +236 -0
  173. package/lib/exercises/pc/mathExosInPC.d.ts +4 -4
  174. package/lib/exercises/pc/mathExosInPC.d.ts.map +1 -1
  175. package/lib/exercises/pc/mathExosInPC.js +4 -4
  176. package/lib/index.d.ts +239 -45
  177. package/lib/index.d.ts.map +1 -1
  178. package/lib/math/geometry/spacePoint.d.ts +10 -0
  179. package/lib/math/geometry/spacePoint.d.ts.map +1 -1
  180. package/lib/math/geometry/spacePoint.js +13 -0
  181. package/lib/tree/nodes/operators/substractNode.d.ts +1 -0
  182. package/lib/tree/nodes/operators/substractNode.d.ts.map +1 -1
  183. package/lib/tree/nodes/operators/substractNode.js +6 -0
  184. package/package.json +1 -1
@@ -0,0 +1,12 @@
1
+ import { Exercise } from "../../../exercises/exercise.js";
2
+ type Identifiers = {
3
+ strStart: string;
4
+ repeatCount: number;
5
+ strBoundLow: string;
6
+ strBoundHigh: string;
7
+ arrStrAppend: string[];
8
+ arrRand: number[];
9
+ };
10
+ export declare const scratchStringLoopCond2: Exercise<Identifiers>;
11
+ export {};
12
+ //# sourceMappingURL=scratchStringLoopCond2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scratchStringLoopCond2.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/scratch/scratchStringLoopCond2.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAeT,MAAM,6BAA6B,CAAC;AAgBrC,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB,CAAC;AAgTF,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAAC,WAAW,CAmBxD,CAAC"}
@@ -0,0 +1,273 @@
1
+ import { addValidProp, shuffleProps, tryToAddWrongProp, propWhile, } 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
+ const getStrScratchForRand = (rand, strAppend) => {
8
+ switch (rand) {
9
+ case 0:
10
+ return ` mettre [x v] à (regrouper (x) et [${strAppend}])`;
11
+ case 1:
12
+ return ` mettre [x v] à (regrouper [${strAppend}] et (x))`;
13
+ }
14
+ };
15
+ const getInstruction = (identifiers) => {
16
+ const { strStart, repeatCount, arrStrAppend, strBoundLow, strBoundHigh, arrRand, } = identifiers;
17
+ return `On considère le programme Scratch ci-dessous :
18
+
19
+ <svg id="scratch">
20
+ quand @greenFlag est cliqué
21
+ mettre [x v] à [${strStart}]
22
+ répéter (${repeatCount}) fois
23
+ si <(lettre [1] de (x)) = [${strBoundLow}]> alors
24
+ ${getStrScratchForRand(arrRand[0], arrStrAppend[0])}
25
+ sinon
26
+ si <(lettre (longueur de (x)) de (x)) = [${strBoundHigh}]> alors
27
+ ${getStrScratchForRand(arrRand[1], arrStrAppend[1])}
28
+ sinon
29
+ ${getStrScratchForRand(arrRand[2], arrStrAppend[2])}
30
+ </svg>
31
+
32
+ Quelle est la valeur de $x$ à la fin de l'exécution du programme ?`;
33
+ };
34
+ const getFunctionForScratchProgram = (identifiers) => {
35
+ const { strStart, repeatCount, arrStrAppend, arrRand, strBoundHigh, strBoundLow, } = identifiers;
36
+ return (_) => {
37
+ const outDict = {};
38
+ //init
39
+ let x;
40
+ x = strStart;
41
+ outDict[0] = {
42
+ x,
43
+ };
44
+ function strForXAndRandAndStrAppend(x, rand, strAppend) {
45
+ switch (rand) {
46
+ case 0:
47
+ return x + strAppend;
48
+ case 1:
49
+ return strAppend + x;
50
+ default:
51
+ throw new Error("unsupported rand: " + rand);
52
+ }
53
+ }
54
+ //loop
55
+ let counter = 0;
56
+ while (counter < repeatCount) {
57
+ counter++;
58
+ //inside of loop
59
+ {
60
+ if (x[0] === strBoundLow) {
61
+ x = strForXAndRandAndStrAppend(x, arrRand[0], arrStrAppend[0]);
62
+ }
63
+ else if (x[x.length - 1] === strBoundHigh) {
64
+ x = strForXAndRandAndStrAppend(x, arrRand[1], arrStrAppend[1]);
65
+ }
66
+ else {
67
+ x = strForXAndRandAndStrAppend(x, arrRand[2], arrStrAppend[2]);
68
+ }
69
+ }
70
+ //store step dict
71
+ outDict[counter] = {
72
+ x,
73
+ };
74
+ }
75
+ //convenience: store last step in -1
76
+ outDict[-1] = outDict[Math.max(...Object.keys(outDict).map((k) => +k))];
77
+ return outDict;
78
+ };
79
+ };
80
+ const getAnswer = (identifiers) => {
81
+ return getFunctionForScratchProgram(identifiers)(identifiers)[-1].x;
82
+ };
83
+ const getHint = () => {
84
+ return `La valeur de la variable $x$ change au cours de l'exécution du programme.
85
+ À chaque itération,
86
+ détermine comment la variable évolue.
87
+ On te demande de t'intéresser à la première lettre et à la dernière lettre de $x$.`;
88
+ };
89
+ const getCorrection = (identifiers) => {
90
+ const { arrRand, arrStrAppend, strBoundHigh, strBoundLow } = identifiers;
91
+ const dictSteps = getFunctionForScratchProgram(identifiers)(identifiers);
92
+ return `Initialement, $x$ vaut $${dictSteps[0].x}$.
93
+
94
+ ${Object.keys(dictSteps)
95
+ .map((k) => +k)
96
+ .filter((k) => k > 0)
97
+ .map((k) => {
98
+ const x = dictSteps[k - 1].x;
99
+ const isCondition1Verified = x[0] === strBoundLow;
100
+ const isCondition2Verified = x[x.length - 1] === strBoundHigh;
101
+ const indexCondition = isCondition1Verified
102
+ ? 0
103
+ : isCondition2Verified
104
+ ? 1
105
+ : 2;
106
+ const rand = arrRand[indexCondition];
107
+ const strAppend1 = arrStrAppend[indexCondition];
108
+ return `Itération n°$${k}$ :
109
+
110
+ Au début, $x$ vaut $${x}$.
111
+
112
+ La première lettre de $x$ est $${x[0]}$.
113
+
114
+ La première condition ${isCondition1Verified ? "est vérifiée" : "n'est pas vérifiée"}.
115
+
116
+ ${(() => {
117
+ if (isCondition1Verified) {
118
+ return ``;
119
+ }
120
+ else {
121
+ return `La dernière lettre de $x$ est $${x[x.length - 1]}$.
122
+
123
+ La deuxième condition ${isCondition2Verified ? "est vérifiée" : "n'est pas vérifiée"}.`;
124
+ }
125
+ })()}
126
+
127
+ On va affecter à $x$ la chaîne de caractères composée par le regroupement de ${(() => {
128
+ switch (rand) {
129
+ case 0:
130
+ return `$${dictSteps[k - 1].x}$ et de $${strAppend1}$`;
131
+ case 1:
132
+ return `$${strAppend1}$ et de $${dictSteps[k - 1].x}$`;
133
+ default:
134
+ throw new Error("unsupported rand: " + rand);
135
+ }
136
+ })()}.
137
+
138
+ $x$ vaut maintenant $${dictSteps[k].x}$.`;
139
+ }).join(`
140
+
141
+ `)}
142
+
143
+ À la fin de l'exécution du programme, $x$ vaut donc $${dictSteps[-1].x}$.`;
144
+ };
145
+ const getPropositions = (n, { answer, ...identifiers }) => {
146
+ const { strStart, repeatCount, arrRand, arrStrAppend } = identifiers;
147
+ const propositions = [];
148
+ addValidProp(propositions, answer);
149
+ //toggle on all checks
150
+ {
151
+ const identifiersWrong = Object.assign({}, identifiers, {
152
+ arrRand: arrRand.toReversed(),
153
+ arrStrAppend: arrStrAppend.toReversed(),
154
+ });
155
+ const texWrong = getAnswer(identifiersWrong);
156
+ tryToAddWrongProp(propositions, texWrong);
157
+ }
158
+ //ABB instead of BBA
159
+ if (arrRand.includes(0) || arrRand.includes(1)) {
160
+ const identifiersWrong = Object.assign({}, identifiers, {
161
+ arrRand: arrRand.map((rand) => (rand === 0 ? 1 : rand === 1 ? 0 : rand)),
162
+ arrStrAppend: arrStrAppend.toReversed(),
163
+ });
164
+ const texWrong = getAnswer(identifiersWrong);
165
+ tryToAddWrongProp(propositions, texWrong);
166
+ }
167
+ //wrong repeatCount
168
+ {
169
+ const identifiersWrong = Object.assign({}, identifiers, {
170
+ repeatCount: repeatCount - 1,
171
+ });
172
+ const texWrong = getAnswer(identifiersWrong);
173
+ tryToAddWrongProp(propositions, texWrong);
174
+ }
175
+ //strStart
176
+ tryToAddWrongProp(propositions, strStart);
177
+ //filler
178
+ propWhile(propositions, n, () => {
179
+ [...Array(repeatCount + 2).keys()].forEach((repeatCountW) => {
180
+ let strWrong = strStart;
181
+ [...Array(repeatCountW).keys()].forEach(() => {
182
+ const strAppend = random(arrStrAppend);
183
+ if (coinFlip()) {
184
+ strWrong = strWrong + strAppend;
185
+ }
186
+ else {
187
+ strWrong = strAppend + strWrong;
188
+ }
189
+ });
190
+ tryToAddWrongProp(propositions, strWrong);
191
+ });
192
+ });
193
+ return shuffleProps(propositions, n);
194
+ };
195
+ const getKeys = () => {
196
+ return ["A", "B", "C", "D"];
197
+ };
198
+ const isAnswerValid = (ans, { answer }) => {
199
+ return ans === answer;
200
+ };
201
+ const getScratchStringLoopCond2Question = () => {
202
+ const arrRand = randomMany([0, 1, 2, 3], 3).map((i) => i % 2);
203
+ function createRandomStr(length) {
204
+ return [...Array(length).keys()].reduce((acc, _) => acc + random(["A", "B", "C", "D"]), "");
205
+ }
206
+ const repeatCount = randint(2, 5);
207
+ const strStart = createRandomStr(randint(1, 3));
208
+ let arrStrAppend;
209
+ {
210
+ let counter = -1;
211
+ let isValid = false;
212
+ while (!isValid && counter < 100) {
213
+ counter++;
214
+ const arrStrAppendCandidate = arrRand.map(() => createRandomStr(randint(1, 3)));
215
+ isValid = [...new Set(arrStrAppendCandidate)].length >= 2;
216
+ if (isValid) {
217
+ arrStrAppend = arrStrAppendCandidate;
218
+ }
219
+ }
220
+ if (!isValid) {
221
+ arrStrAppend = ["AB", "C", "DB"];
222
+ }
223
+ }
224
+ const [strBoundHigh, strBoundLow] = shuffle([
225
+ strStart,
226
+ random(arrStrAppend),
227
+ ]).map((str, i) => {
228
+ if (i === 0) {
229
+ return str[str.length - 1];
230
+ }
231
+ else {
232
+ return str[0];
233
+ }
234
+ });
235
+ const identifiers = {
236
+ strStart,
237
+ repeatCount,
238
+ arrStrAppend: arrStrAppend,
239
+ arrRand,
240
+ strBoundHigh,
241
+ strBoundLow,
242
+ };
243
+ return getQuestionFromIdentifiers(identifiers);
244
+ };
245
+ const getQuestionFromIdentifiers = (identifiers) => {
246
+ return {
247
+ answer: getAnswer(identifiers),
248
+ instruction: getInstruction(identifiers),
249
+ keys: getKeys(identifiers),
250
+ answerFormat: "tex",
251
+ identifiers,
252
+ hint: getHint(identifiers),
253
+ correction: getCorrection(identifiers),
254
+ };
255
+ };
256
+ export const scratchStringLoopCond2 = {
257
+ id: "scratchStringLoopCond2",
258
+ connector: "=",
259
+ label: "Utiliser une condition dans une boucle avec une chaîne de caractères en Scratch ($2$)",
260
+ isSingleStep: true,
261
+ generator: (nb, opts) => getDistinctQuestions(() => getScratchStringLoopCond2Question(opts), nb),
262
+ qcmTimer: 60,
263
+ freeTimer: 60,
264
+ getPropositions,
265
+ isAnswerValid,
266
+ subject: "Mathématiques",
267
+ getInstruction,
268
+ getHint,
269
+ getCorrection,
270
+ getAnswer,
271
+ getQuestionFromIdentifiers,
272
+ hasHintAndCorrection: true,
273
+ };
@@ -0,0 +1,12 @@
1
+ import { Exercise } from "../../../exercises/exercise.js";
2
+ type Identifiers = {
3
+ strStart: string;
4
+ repeatCount: number;
5
+ strIncludes1: string;
6
+ strIncludes2: string;
7
+ arrStrAppend: string[];
8
+ arrRand: number[];
9
+ };
10
+ export declare const scratchStringLoopCond3: Exercise<Identifiers>;
11
+ export {};
12
+ //# sourceMappingURL=scratchStringLoopCond3.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scratchStringLoopCond3.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/scratch/scratchStringLoopCond3.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAeT,MAAM,6BAA6B,CAAC;AAerC,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB,CAAC;AA0TF,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAAC,WAAW,CAmBxD,CAAC"}
@@ -0,0 +1,275 @@
1
+ import { addValidProp, shuffleProps, tryToAddWrongProp, propWhile, } 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
+ const getStrScratchForRand = (rand, strAppend) => {
7
+ switch (rand) {
8
+ case 0:
9
+ return ` mettre [x v] à (regrouper (x) et [${strAppend}])`;
10
+ case 1:
11
+ return ` mettre [x v] à (regrouper [${strAppend}] et (x))`;
12
+ }
13
+ };
14
+ const getInstruction = (identifiers) => {
15
+ const { strStart, repeatCount, arrStrAppend, strIncludes1, strIncludes2, arrRand, } = identifiers;
16
+ return `On considère le programme Scratch ci-dessous :
17
+
18
+ <svg id="scratch">
19
+ quand @greenFlag est cliqué
20
+ mettre [x v] à [${strStart}]
21
+ répéter (${repeatCount}) fois
22
+ si <(x) contient [${strIncludes1}] ?> alors
23
+ ${getStrScratchForRand(arrRand[0], arrStrAppend[0])}
24
+ sinon
25
+ si <(x) contient [${strIncludes2}] ?> alors
26
+ ${getStrScratchForRand(arrRand[1], arrStrAppend[1])}
27
+ sinon
28
+ ${getStrScratchForRand(arrRand[2], arrStrAppend[2])}
29
+ </svg>
30
+
31
+ Quelle est la valeur de $x$ à la fin de l'exécution du programme ?`;
32
+ };
33
+ const getFunctionForScratchProgram = (identifiers) => {
34
+ const { strStart, repeatCount, arrStrAppend, arrRand, strIncludes1, strIncludes2, } = identifiers;
35
+ return (_) => {
36
+ const outDict = {};
37
+ //init
38
+ let x;
39
+ x = strStart;
40
+ outDict[0] = {
41
+ x,
42
+ };
43
+ function strForXAndRandAndStrAppend(x, rand, strAppend) {
44
+ switch (rand) {
45
+ case 0:
46
+ return x + strAppend;
47
+ case 1:
48
+ return strAppend + x;
49
+ default:
50
+ throw new Error("unsupported rand: " + rand);
51
+ }
52
+ }
53
+ //loop
54
+ let counter = 0;
55
+ while (counter < repeatCount) {
56
+ counter++;
57
+ //inside of loop
58
+ {
59
+ if (x.includes(strIncludes1)) {
60
+ x = strForXAndRandAndStrAppend(x, arrRand[0], arrStrAppend[0]);
61
+ }
62
+ else if (x.includes(strIncludes2)) {
63
+ x = strForXAndRandAndStrAppend(x, arrRand[1], arrStrAppend[1]);
64
+ }
65
+ else {
66
+ x = strForXAndRandAndStrAppend(x, arrRand[2], arrStrAppend[2]);
67
+ }
68
+ }
69
+ //store step dict
70
+ outDict[counter] = {
71
+ x,
72
+ };
73
+ }
74
+ //convenience: store last step in -1
75
+ outDict[-1] = outDict[Math.max(...Object.keys(outDict).map((k) => +k))];
76
+ return outDict;
77
+ };
78
+ };
79
+ const getAnswer = (identifiers) => {
80
+ return getFunctionForScratchProgram(identifiers)(identifiers)[-1].x;
81
+ };
82
+ const getHint = () => {
83
+ return `La valeur de la variable $x$ change au cours de l'exécution du programme.
84
+ À chaque itération,
85
+ détermine comment la variable évolue.`;
86
+ };
87
+ const getCorrection = (identifiers) => {
88
+ const { arrRand, arrStrAppend, strIncludes1, strIncludes2 } = identifiers;
89
+ const dictSteps = getFunctionForScratchProgram(identifiers)(identifiers);
90
+ return `Initialement, $x$ vaut $${dictSteps[0].x}$.
91
+
92
+ ${Object.keys(dictSteps)
93
+ .map((k) => +k)
94
+ .filter((k) => k > 0)
95
+ .map((k) => {
96
+ const x = dictSteps[k - 1].x;
97
+ const isCondition1Verified = x.includes(strIncludes1);
98
+ const isCondition2Verified = x.includes(strIncludes2);
99
+ const indexCondition = isCondition1Verified
100
+ ? 0
101
+ : isCondition2Verified
102
+ ? 1
103
+ : 2;
104
+ const rand = arrRand[indexCondition];
105
+ const strAppend1 = arrStrAppend[indexCondition];
106
+ return `Itération n°$${k}$ :
107
+
108
+ Au début, $x$ vaut $${x}$.
109
+
110
+ ${isCondition1Verified
111
+ ? `$x$ contient $${strIncludes1}$.`
112
+ : `$x$ ne contient pas $${strIncludes1}$.`}
113
+
114
+ La première condition ${isCondition1Verified ? "est vérifiée" : "n'est pas vérifiée"}.
115
+
116
+ ${(() => {
117
+ if (isCondition1Verified) {
118
+ return ``;
119
+ }
120
+ else {
121
+ return `${isCondition2Verified
122
+ ? `$x$ contient $${strIncludes2}$.`
123
+ : `$x$ ne contient pas $${strIncludes2}$.`}
124
+
125
+ La deuxième condition ${isCondition2Verified ? "est vérifiée" : "n'est pas vérifiée"}.`;
126
+ }
127
+ })()}
128
+
129
+ On va affecter à $x$ la chaîne de caractères composée par le regroupement de ${(() => {
130
+ switch (rand) {
131
+ case 0:
132
+ return `$${dictSteps[k - 1].x}$ et de $${strAppend1}$`;
133
+ case 1:
134
+ return `$${strAppend1}$ et de $${dictSteps[k - 1].x}$`;
135
+ default:
136
+ throw new Error("unsupported rand: " + rand);
137
+ }
138
+ })()}.
139
+
140
+ $x$ vaut maintenant $${dictSteps[k].x}$.`;
141
+ }).join(`
142
+
143
+ `)}
144
+
145
+ À la fin de l'exécution du programme, $x$ vaut donc $${dictSteps[-1].x}$.`;
146
+ };
147
+ const getPropositions = (n, { answer, ...identifiers }) => {
148
+ const { strStart, repeatCount, arrRand, arrStrAppend } = identifiers;
149
+ const propositions = [];
150
+ addValidProp(propositions, answer);
151
+ //toggle on all checks
152
+ {
153
+ const identifiersWrong = Object.assign({}, identifiers, {
154
+ arrRand: arrRand.toReversed(),
155
+ arrStrAppend: arrStrAppend.toReversed(),
156
+ });
157
+ const texWrong = getAnswer(identifiersWrong);
158
+ tryToAddWrongProp(propositions, texWrong);
159
+ }
160
+ //ABB instead of BBA
161
+ if (arrRand.includes(0) || arrRand.includes(1)) {
162
+ const identifiersWrong = Object.assign({}, identifiers, {
163
+ arrRand: arrRand.map((rand) => (rand === 0 ? 1 : rand === 1 ? 0 : rand)),
164
+ arrStrAppend: arrStrAppend.toReversed(),
165
+ });
166
+ const texWrong = getAnswer(identifiersWrong);
167
+ tryToAddWrongProp(propositions, texWrong);
168
+ }
169
+ //wrong repeatCount
170
+ {
171
+ const identifiersWrong = Object.assign({}, identifiers, {
172
+ repeatCount: repeatCount - 1,
173
+ });
174
+ const texWrong = getAnswer(identifiersWrong);
175
+ tryToAddWrongProp(propositions, texWrong);
176
+ }
177
+ //strStart
178
+ tryToAddWrongProp(propositions, strStart);
179
+ //filler
180
+ propWhile(propositions, n, () => {
181
+ [...Array(repeatCount + 2).keys()].forEach((repeatCountW) => {
182
+ let strWrong = strStart;
183
+ [...Array(repeatCountW).keys()].forEach(() => {
184
+ const strAppend = random(arrStrAppend);
185
+ if (coinFlip()) {
186
+ strWrong = strWrong + strAppend;
187
+ }
188
+ else {
189
+ strWrong = strAppend + strWrong;
190
+ }
191
+ });
192
+ tryToAddWrongProp(propositions, strWrong);
193
+ });
194
+ });
195
+ return shuffleProps(propositions, n);
196
+ };
197
+ const getKeys = () => {
198
+ return ["A", "B", "C", "D"];
199
+ };
200
+ const isAnswerValid = (ans, { answer }) => {
201
+ return ans === answer;
202
+ };
203
+ const getScratchStringLoopCond2Question = () => {
204
+ const arrRand = randomMany([0, 1, 2, 3], 3).map((i) => i % 2);
205
+ function createRandomStr(length) {
206
+ return [...Array(length).keys()].reduce((acc, _) => acc + random(["A", "B", "C", "D"]), "");
207
+ }
208
+ const repeatCount = randint(2, 5);
209
+ const strStart = createRandomStr(randint(1, 3));
210
+ let arrStrAppend;
211
+ {
212
+ let counter = -1;
213
+ let isValid = false;
214
+ while (!isValid && counter < 100) {
215
+ counter++;
216
+ const arrStrAppendCandidate = arrRand.map(() => createRandomStr(randint(1, 3)));
217
+ isValid = [...new Set(arrStrAppendCandidate)].length >= 2;
218
+ if (isValid) {
219
+ arrStrAppend = arrStrAppendCandidate;
220
+ }
221
+ }
222
+ if (!isValid) {
223
+ arrStrAppend = ["AB", "C", "DB"];
224
+ }
225
+ }
226
+ const strIncludesPool = arrRand.map((rand, i) => {
227
+ if (rand === 0) {
228
+ return [strStart[strStart.length - 1], arrStrAppend[i][0]].join("");
229
+ }
230
+ else {
231
+ return [arrStrAppend[i][arrStrAppend[i].length - 1], strStart[0]].join("");
232
+ }
233
+ });
234
+ const [strIncludes1, strIncludes2] = coinFlip()
235
+ ? randomMany(strIncludesPool, 2)
236
+ : [random(strIncludesPool), random(["A", "B", "C", "D"])];
237
+ const identifiers = {
238
+ strStart,
239
+ repeatCount,
240
+ arrStrAppend: arrStrAppend,
241
+ arrRand,
242
+ strIncludes1,
243
+ strIncludes2,
244
+ };
245
+ return getQuestionFromIdentifiers(identifiers);
246
+ };
247
+ const getQuestionFromIdentifiers = (identifiers) => {
248
+ return {
249
+ answer: getAnswer(identifiers),
250
+ instruction: getInstruction(identifiers),
251
+ keys: getKeys(identifiers),
252
+ answerFormat: "tex",
253
+ identifiers,
254
+ hint: getHint(identifiers),
255
+ correction: getCorrection(identifiers),
256
+ };
257
+ };
258
+ export const scratchStringLoopCond3 = {
259
+ id: "scratchStringLoopCond3",
260
+ connector: "=",
261
+ label: "Utiliser une condition dans une boucle avec une chaîne de caractères en Scratch ($3$)",
262
+ isSingleStep: true,
263
+ generator: (nb, opts) => getDistinctQuestions(() => getScratchStringLoopCond2Question(opts), nb),
264
+ qcmTimer: 60,
265
+ freeTimer: 60,
266
+ getPropositions,
267
+ isAnswerValid,
268
+ subject: "Mathématiques",
269
+ getInstruction,
270
+ getHint,
271
+ getCorrection,
272
+ getAnswer,
273
+ getQuestionFromIdentifiers,
274
+ hasHintAndCorrection: true,
275
+ };
@@ -0,0 +1,10 @@
1
+ import { Exercise } from "../../../exercises/exercise.js";
2
+ type Identifiers = {
3
+ xStart: number;
4
+ yStart: number;
5
+ tStart: number;
6
+ steps: string[][];
7
+ };
8
+ export declare const scratchSwapUsingTmp: Exercise<Identifiers>;
9
+ export {};
10
+ //# sourceMappingURL=scratchSwapUsingTmp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scratchSwapUsingTmp.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/scratch/scratchSwapUsingTmp.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAeT,MAAM,6BAA6B,CAAC;AAQrC,KAAK,WAAW,GAAG;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC;CACnB,CAAC;AAoNF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,WAAW,CAkBrD,CAAC"}