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.
- package/lib/exercises/math/calcul/arithmetics/primeNumbersAffirmations.js +1 -1
- package/lib/exercises/math/calculLitteral/equation/equa1.d.ts +4 -1
- package/lib/exercises/math/calculLitteral/equation/equa1.d.ts.map +1 -1
- package/lib/exercises/math/calculLitteral/equation/equa1.js +27 -7
- package/lib/exercises/math/calculLitteral/equation/equa2.d.ts +1 -0
- package/lib/exercises/math/calculLitteral/equation/equa2.d.ts.map +1 -1
- package/lib/exercises/math/calculLitteral/equation/equa2.js +18 -1
- package/lib/exercises/math/calculLitteral/equation/equa3.d.ts +4 -1
- package/lib/exercises/math/calculLitteral/equation/equa3.d.ts.map +1 -1
- package/lib/exercises/math/calculLitteral/equation/equa3.js +26 -6
- package/lib/exercises/math/calculLitteral/equation/equa4.d.ts +4 -1
- package/lib/exercises/math/calculLitteral/equation/equa4.d.ts.map +1 -1
- package/lib/exercises/math/calculLitteral/equation/equa4.js +27 -7
- package/lib/exercises/math/calculLitteral/equation/firstDegree/equa1.d.ts +14 -0
- package/lib/exercises/math/calculLitteral/equation/firstDegree/equa1.d.ts.map +1 -0
- package/lib/exercises/math/calculLitteral/equation/firstDegree/equa1.js +129 -0
- package/lib/exercises/math/calculLitteral/equation/firstDegree/equa2.d.ts +18 -0
- package/lib/exercises/math/calculLitteral/equation/firstDegree/equa2.d.ts.map +1 -0
- package/lib/exercises/math/calculLitteral/equation/firstDegree/equa2.js +167 -0
- package/lib/exercises/math/calculLitteral/equation/firstDegree/equa3.d.ts +15 -0
- package/lib/exercises/math/calculLitteral/equation/firstDegree/equa3.d.ts.map +1 -0
- package/lib/exercises/math/calculLitteral/equation/firstDegree/equa3.js +129 -0
- package/lib/exercises/math/calculLitteral/equation/firstDegree/equa4.d.ts +16 -0
- package/lib/exercises/math/calculLitteral/equation/firstDegree/equa4.d.ts.map +1 -0
- package/lib/exercises/math/calculLitteral/equation/firstDegree/equa4.js +124 -0
- package/lib/exercises/math/calculLitteral/equation/firstDegree/firstDegreeEquationIntType1.d.ts +9 -0
- package/lib/exercises/math/calculLitteral/equation/firstDegree/firstDegreeEquationIntType1.d.ts.map +1 -0
- package/lib/exercises/math/calculLitteral/equation/firstDegree/firstDegreeEquationIntType1.js +107 -0
- package/lib/exercises/math/calculLitteral/equation/firstDegree/firstDegreeEquationIntType2.d.ts +10 -0
- package/lib/exercises/math/calculLitteral/equation/firstDegree/firstDegreeEquationIntType2.d.ts.map +1 -0
- package/lib/exercises/math/calculLitteral/equation/firstDegree/firstDegreeEquationIntType2.js +108 -0
- package/lib/exercises/math/calculLitteral/equation/firstDegree/firstDegreeEquationIntType3.d.ts +11 -0
- package/lib/exercises/math/calculLitteral/equation/firstDegree/firstDegreeEquationIntType3.d.ts.map +1 -0
- package/lib/exercises/math/calculLitteral/equation/firstDegree/firstDegreeEquationIntType3.js +104 -0
- package/lib/exercises/math/calculLitteral/equation/firstDegree/index.d.ts +8 -0
- package/lib/exercises/math/calculLitteral/equation/firstDegree/index.d.ts.map +1 -0
- package/lib/exercises/math/calculLitteral/equation/firstDegree/index.js +7 -0
- package/lib/exercises/math/calculLitteral/equation/index.d.ts +1 -7
- package/lib/exercises/math/calculLitteral/equation/index.d.ts.map +1 -1
- package/lib/exercises/math/calculLitteral/equation/index.js +1 -7
- package/lib/exercises/math/dataRepresentations/histogram/etendueHistogram.d.ts +8 -0
- package/lib/exercises/math/dataRepresentations/histogram/etendueHistogram.d.ts.map +1 -0
- package/lib/exercises/math/dataRepresentations/histogram/etendueHistogram.js +175 -0
- package/lib/exercises/math/dataRepresentations/histogram/histogramCommenting.d.ts +9 -0
- package/lib/exercises/math/dataRepresentations/histogram/histogramCommenting.d.ts.map +1 -0
- package/lib/exercises/math/dataRepresentations/histogram/histogramCommenting.js +250 -0
- package/lib/exercises/math/dataRepresentations/histogram/histogramFillDataTableFromHistogramData.d.ts +9 -0
- package/lib/exercises/math/dataRepresentations/histogram/histogramFillDataTableFromHistogramData.d.ts.map +1 -0
- package/lib/exercises/math/dataRepresentations/histogram/histogramFillDataTableFromHistogramData.js +173 -0
- package/lib/exercises/math/dataRepresentations/histogram/histogramIsSameData.d.ts +14 -0
- package/lib/exercises/math/dataRepresentations/histogram/histogramIsSameData.d.ts.map +1 -0
- package/lib/exercises/math/dataRepresentations/histogram/histogramIsSameData.js +232 -0
- package/lib/exercises/math/dataRepresentations/histogram/histogramReading.d.ts +9 -0
- package/lib/exercises/math/dataRepresentations/histogram/histogramReading.d.ts.map +1 -0
- package/lib/exercises/math/dataRepresentations/histogram/histogramReading.js +163 -0
- package/lib/exercises/math/dataRepresentations/histogram/index.d.ts +6 -0
- package/lib/exercises/math/dataRepresentations/histogram/index.d.ts.map +1 -0
- package/lib/exercises/math/dataRepresentations/histogram/index.js +5 -0
- package/lib/exercises/math/dataRepresentations/index.d.ts +1 -1
- package/lib/exercises/math/dataRepresentations/index.d.ts.map +1 -1
- package/lib/exercises/math/dataRepresentations/index.js +1 -1
- package/lib/exercises/math/functions/affines/leadingCoeffAndOriginOrdinate.d.ts +4 -1
- package/lib/exercises/math/functions/affines/leadingCoeffAndOriginOrdinate.d.ts.map +1 -1
- package/lib/exercises/math/functions/affines/leadingCoeffAndOriginOrdinate.js +19 -4
- package/lib/exercises/math/functions/affines/leadingCoefficient.d.ts +1 -0
- package/lib/exercises/math/functions/affines/leadingCoefficient.d.ts.map +1 -1
- package/lib/exercises/math/functions/affines/leadingCoefficient.js +13 -1
- package/lib/exercises/math/functions/affines/recognizeAffineGraph.d.ts +4 -1
- package/lib/exercises/math/functions/affines/recognizeAffineGraph.d.ts.map +1 -1
- package/lib/exercises/math/functions/affines/recognizeAffineGraph.js +19 -4
- package/lib/exercises/math/geometry/euclidian/pythagoreOrThales.d.ts +4 -1
- package/lib/exercises/math/geometry/euclidian/pythagoreOrThales.d.ts.map +1 -1
- package/lib/exercises/math/geometry/euclidian/pythagoreOrThales.js +18 -3
- package/lib/exercises/math/geometry/triangles/index.d.ts +1 -0
- package/lib/exercises/math/geometry/triangles/index.d.ts.map +1 -1
- package/lib/exercises/math/geometry/triangles/index.js +1 -0
- package/lib/exercises/math/geometry/triangles/similar/index.d.ts +4 -0
- package/lib/exercises/math/geometry/triangles/similar/index.d.ts.map +1 -0
- package/lib/exercises/math/geometry/triangles/similar/index.js +3 -0
- package/lib/exercises/math/geometry/triangles/similar/isSimilarTrianglesWithAngles.d.ts +10 -0
- package/lib/exercises/math/geometry/triangles/similar/isSimilarTrianglesWithAngles.d.ts.map +1 -0
- package/lib/exercises/math/geometry/triangles/similar/isSimilarTrianglesWithAngles.js +122 -0
- package/lib/exercises/math/geometry/triangles/similar/isSimilarTrianglesWrtSideLengths.d.ts +15 -0
- package/lib/exercises/math/geometry/triangles/similar/isSimilarTrianglesWrtSideLengths.d.ts.map +1 -0
- package/lib/exercises/math/geometry/triangles/similar/isSimilarTrianglesWrtSideLengths.js +351 -0
- package/lib/exercises/math/geometry/triangles/similar/placeSegmentsOfSimilarTriangle.d.ts +11 -0
- package/lib/exercises/math/geometry/triangles/similar/placeSegmentsOfSimilarTriangle.d.ts.map +1 -0
- package/lib/exercises/math/geometry/triangles/similar/placeSegmentsOfSimilarTriangle.js +311 -0
- package/lib/exercises/math/probaStat/basicProbas/calculateProbaFromProbaLaw.d.ts +10 -0
- package/lib/exercises/math/probaStat/basicProbas/calculateProbaFromProbaLaw.d.ts.map +1 -0
- package/lib/exercises/math/probaStat/basicProbas/calculateProbaFromProbaLaw.js +128 -0
- package/lib/exercises/math/probaStat/basicProbas/findEffectifFromProba.d.ts +9 -0
- package/lib/exercises/math/probaStat/basicProbas/findEffectifFromProba.d.ts.map +1 -0
- package/lib/exercises/math/probaStat/basicProbas/findEffectifFromProba.js +109 -0
- package/lib/exercises/math/probaStat/basicProbas/index.d.ts +2 -0
- package/lib/exercises/math/probaStat/basicProbas/index.d.ts.map +1 -1
- package/lib/exercises/math/probaStat/basicProbas/index.js +2 -0
- package/lib/exercises/math/scratch/index.d.ts +13 -0
- package/lib/exercises/math/scratch/index.d.ts.map +1 -1
- package/lib/exercises/math/scratch/index.js +14 -0
- package/lib/exercises/math/scratch/scratchCond1.d.ts +25 -0
- package/lib/exercises/math/scratch/scratchCond1.d.ts.map +1 -0
- package/lib/exercises/math/scratch/scratchCond1.js +290 -0
- package/lib/exercises/math/scratch/scratchFunction1.d.ts +9 -0
- package/lib/exercises/math/scratch/scratchFunction1.d.ts.map +1 -0
- package/lib/exercises/math/scratch/scratchFunction1.js +199 -0
- package/lib/exercises/math/scratch/scratchLoop1.d.ts +10 -0
- package/lib/exercises/math/scratch/scratchLoop1.d.ts.map +1 -0
- package/lib/exercises/math/scratch/scratchLoop1.js +207 -0
- package/lib/exercises/math/scratch/scratchLoopCond1.d.ts +12 -0
- package/lib/exercises/math/scratch/scratchLoopCond1.d.ts.map +1 -0
- package/lib/exercises/math/scratch/scratchLoopCond1.js +236 -0
- package/lib/exercises/math/scratch/scratchLoopCond2.d.ts +14 -0
- package/lib/exercises/math/scratch/scratchLoopCond2.d.ts.map +1 -0
- package/lib/exercises/math/scratch/scratchLoopCond2.js +219 -0
- package/lib/exercises/math/scratch/scratchOperations1.d.ts +8 -0
- package/lib/exercises/math/scratch/scratchOperations1.d.ts.map +1 -0
- package/lib/exercises/math/scratch/scratchOperations1.js +245 -0
- package/lib/exercises/math/scratch/scratchOperations2.d.ts +10 -0
- package/lib/exercises/math/scratch/scratchOperations2.d.ts.map +1 -0
- package/lib/exercises/math/scratch/scratchOperations2.js +324 -0
- package/lib/exercises/math/scratch/scratchPrintXY.d.ts +9 -0
- package/lib/exercises/math/scratch/scratchPrintXY.d.ts.map +1 -0
- package/lib/exercises/math/scratch/scratchPrintXY.js +194 -0
- package/lib/exercises/math/scratch/scratchStringLoop.d.ts +10 -0
- package/lib/exercises/math/scratch/scratchStringLoop.d.ts.map +1 -0
- package/lib/exercises/math/scratch/scratchStringLoop.js +192 -0
- package/lib/exercises/math/scratch/scratchStringLoopCond.d.ts +12 -0
- package/lib/exercises/math/scratch/scratchStringLoopCond.d.ts.map +1 -0
- package/lib/exercises/math/scratch/scratchStringLoopCond.js +270 -0
- package/lib/exercises/math/scratch/scratchStringLoopCond2.d.ts +12 -0
- package/lib/exercises/math/scratch/scratchStringLoopCond2.d.ts.map +1 -0
- package/lib/exercises/math/scratch/scratchStringLoopCond2.js +273 -0
- package/lib/exercises/math/scratch/scratchStringLoopCond3.d.ts +12 -0
- package/lib/exercises/math/scratch/scratchStringLoopCond3.d.ts.map +1 -0
- package/lib/exercises/math/scratch/scratchStringLoopCond3.js +275 -0
- package/lib/exercises/math/scratch/scratchSwapUsingTmp.d.ts +10 -0
- package/lib/exercises/math/scratch/scratchSwapUsingTmp.d.ts.map +1 -0
- package/lib/exercises/math/scratch/scratchSwapUsingTmp.js +199 -0
- package/lib/exercises/math/scratch/scratchVarWaterfall.d.ts +10 -0
- package/lib/exercises/math/scratch/scratchVarWaterfall.d.ts.map +1 -0
- package/lib/exercises/math/scratch/scratchVarWaterfall.js +371 -0
- package/lib/exercises/math/spaceGeometry/index.d.ts +1 -0
- package/lib/exercises/math/spaceGeometry/index.d.ts.map +1 -1
- package/lib/exercises/math/spaceGeometry/index.js +1 -0
- package/lib/exercises/math/spaceGeometry/sections/areaOfConeSection.d.ts +14 -0
- package/lib/exercises/math/spaceGeometry/sections/areaOfConeSection.d.ts.map +1 -0
- package/lib/exercises/math/spaceGeometry/sections/areaOfConeSection.js +439 -0
- package/lib/exercises/math/spaceGeometry/sections/areaOfCylinderSection.d.ts +14 -0
- package/lib/exercises/math/spaceGeometry/sections/areaOfCylinderSection.d.ts.map +1 -0
- package/lib/exercises/math/spaceGeometry/sections/areaOfCylinderSection.js +548 -0
- package/lib/exercises/math/spaceGeometry/sections/areaOfRectangularPrismSection.d.ts +11 -0
- package/lib/exercises/math/spaceGeometry/sections/areaOfRectangularPrismSection.d.ts.map +1 -0
- package/lib/exercises/math/spaceGeometry/sections/areaOfRectangularPrismSection.js +360 -0
- package/lib/exercises/math/spaceGeometry/sections/areaOfSphereSection.d.ts +9 -0
- package/lib/exercises/math/spaceGeometry/sections/areaOfSphereSection.d.ts.map +1 -0
- package/lib/exercises/math/spaceGeometry/sections/areaOfSphereSection.js +272 -0
- package/lib/exercises/math/spaceGeometry/sections/index.d.ts +9 -0
- package/lib/exercises/math/spaceGeometry/sections/index.d.ts.map +1 -0
- package/lib/exercises/math/spaceGeometry/sections/index.js +8 -0
- package/lib/exercises/math/spaceGeometry/sections/recognizeSectionsOfCone.d.ts +11 -0
- package/lib/exercises/math/spaceGeometry/sections/recognizeSectionsOfCone.d.ts.map +1 -0
- package/lib/exercises/math/spaceGeometry/sections/recognizeSectionsOfCone.js +266 -0
- package/lib/exercises/math/spaceGeometry/sections/recognizeSectionsOfCylinder.d.ts +11 -0
- package/lib/exercises/math/spaceGeometry/sections/recognizeSectionsOfCylinder.d.ts.map +1 -0
- package/lib/exercises/math/spaceGeometry/sections/recognizeSectionsOfCylinder.js +236 -0
- package/lib/exercises/math/spaceGeometry/sections/recognizeSectionsOfRectangularPrism.d.ts +7 -0
- package/lib/exercises/math/spaceGeometry/sections/recognizeSectionsOfRectangularPrism.d.ts.map +1 -0
- package/lib/exercises/math/spaceGeometry/sections/recognizeSectionsOfRectangularPrism.js +92 -0
- package/lib/exercises/math/spaceGeometry/sections/recognizeSectionsOfSphereOrBall.d.ts +9 -0
- package/lib/exercises/math/spaceGeometry/sections/recognizeSectionsOfSphereOrBall.d.ts.map +1 -0
- package/lib/exercises/math/spaceGeometry/sections/recognizeSectionsOfSphereOrBall.js +236 -0
- package/lib/exercises/pc/mathExosInPC.d.ts +4 -4
- package/lib/exercises/pc/mathExosInPC.d.ts.map +1 -1
- package/lib/exercises/pc/mathExosInPC.js +4 -4
- package/lib/index.d.ts +239 -45
- package/lib/index.d.ts.map +1 -1
- package/lib/math/geometry/spacePoint.d.ts +10 -0
- package/lib/math/geometry/spacePoint.d.ts.map +1 -1
- package/lib/math/geometry/spacePoint.js +13 -0
- package/lib/tree/nodes/operators/substractNode.d.ts +1 -0
- package/lib/tree/nodes/operators/substractNode.d.ts.map +1 -1
- package/lib/tree/nodes/operators/substractNode.js +6 -0
- package/package.json +1 -1
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Exercise } from "../../../exercises/exercise.js";
|
|
2
|
+
import { NodeIdentifiers } from "../../../tree/nodes/nodeConstructor.js";
|
|
3
|
+
type Identifiers = {
|
|
4
|
+
nodeIds: NodeIdentifiers;
|
|
5
|
+
};
|
|
6
|
+
export declare const scratchOperations1: Exercise<Identifiers>;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=scratchOperations1.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scratchOperations1.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/scratch/scratchOperations1.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAeT,MAAM,6BAA6B,CAAC;AAMrC,OAAO,EAEL,eAAe,EAChB,MAAM,qCAAqC,CAAC;AA4F7C,KAAK,WAAW,GAAG;IACjB,OAAO,EAAE,eAAe,CAAC;CAC1B,CAAC;AA+JF,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,WAAW,CAkBpD,CAAC"}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { addValidProp, tryToAddWrongProp, propWhile, shuffleProps, } from "../../../exercises/exercise.js";
|
|
2
|
+
import { getDistinctQuestions } from "../../../exercises/utils/getDistinctQuestions.js";
|
|
3
|
+
import { numberVEA } from "../../../exercises/vea/numberVEA.js";
|
|
4
|
+
import { randint } from "../../../math/utils/random/randint.js";
|
|
5
|
+
import { round } from "../../../math/utils/round.js";
|
|
6
|
+
import { NodeConstructor, } from "../../../tree/nodes/nodeConstructor.js";
|
|
7
|
+
import { isNumberNode } from "../../../tree/nodes/numbers/numberNode.js";
|
|
8
|
+
import { add } from "../../../tree/nodes/operators/addNode.js";
|
|
9
|
+
import { divide } from "../../../tree/nodes/operators/divideNode.js";
|
|
10
|
+
import { multiply } from "../../../tree/nodes/operators/multiplyNode.js";
|
|
11
|
+
import { isOperatorNode, OperatorIds, } from "../../../tree/nodes/operators/operatorNode.js";
|
|
12
|
+
import { substract } from "../../../tree/nodes/operators/substractNode.js";
|
|
13
|
+
import { NodeShuffler } from "../../../tree/utilities/nodeShuffler.js";
|
|
14
|
+
import { random } from "../../../utils/alea/random.js";
|
|
15
|
+
import { handleVEAError } from "../../../utils/errors/handleVEAError.js";
|
|
16
|
+
const createRandomNode = (depth) => {
|
|
17
|
+
let nodeX;
|
|
18
|
+
let nodeY;
|
|
19
|
+
if (depth === 0) {
|
|
20
|
+
return randint(1, 10).toTree();
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
const depthLeft = randint(0, depth);
|
|
24
|
+
const depthRight = depth - 1 - depthLeft;
|
|
25
|
+
[nodeX, nodeY] = [depthLeft, depthRight].map((depthChild) => createRandomNode(depthChild));
|
|
26
|
+
}
|
|
27
|
+
return random([add, substract, multiply, divide])(nodeX, nodeY);
|
|
28
|
+
};
|
|
29
|
+
const getStrScratchblocks = (node) => {
|
|
30
|
+
if (isOperatorNode(node)) {
|
|
31
|
+
const nodeOperator = node;
|
|
32
|
+
const strScratchOperator = (() => {
|
|
33
|
+
switch (nodeOperator.id) {
|
|
34
|
+
case OperatorIds.add:
|
|
35
|
+
return "+";
|
|
36
|
+
case OperatorIds.substract:
|
|
37
|
+
return "-";
|
|
38
|
+
case OperatorIds.multiply:
|
|
39
|
+
return "*";
|
|
40
|
+
case OperatorIds.divide:
|
|
41
|
+
return "/";
|
|
42
|
+
default:
|
|
43
|
+
throw new Error("unsupported id: " + nodeOperator.id);
|
|
44
|
+
}
|
|
45
|
+
})();
|
|
46
|
+
const [strLeft, strRight] = [
|
|
47
|
+
nodeOperator.leftChild,
|
|
48
|
+
nodeOperator.rightChild,
|
|
49
|
+
].map((nodeChild) => {
|
|
50
|
+
return getStrScratchblocks(nodeChild);
|
|
51
|
+
});
|
|
52
|
+
return `(${strLeft}${strScratchOperator}${strRight})`;
|
|
53
|
+
}
|
|
54
|
+
else if (isNumberNode(node)) {
|
|
55
|
+
return `(${node.value.frenchify()})`;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
throw new Error("unsupported nodeType: " + node.type);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const getTexWithParentheses = (node) => {
|
|
62
|
+
if (isOperatorNode(node)) {
|
|
63
|
+
const nodeOperator = node;
|
|
64
|
+
const strScratchOperator = (() => {
|
|
65
|
+
switch (nodeOperator.id) {
|
|
66
|
+
case OperatorIds.add:
|
|
67
|
+
return "+";
|
|
68
|
+
case OperatorIds.substract:
|
|
69
|
+
return "-";
|
|
70
|
+
case OperatorIds.multiply:
|
|
71
|
+
return "\\times";
|
|
72
|
+
case OperatorIds.divide:
|
|
73
|
+
return "\\div";
|
|
74
|
+
default:
|
|
75
|
+
throw new Error("unsupported id: " + nodeOperator.id);
|
|
76
|
+
}
|
|
77
|
+
})();
|
|
78
|
+
const [strLeft, strRight] = [
|
|
79
|
+
nodeOperator.leftChild,
|
|
80
|
+
nodeOperator.rightChild,
|
|
81
|
+
].map((nodeChild) => {
|
|
82
|
+
return getTexWithParentheses(nodeChild);
|
|
83
|
+
});
|
|
84
|
+
return `\\left(${strLeft} \\ ${strScratchOperator} \\ ${strRight}\\right)`;
|
|
85
|
+
}
|
|
86
|
+
else if (isNumberNode(node)) {
|
|
87
|
+
return `${node.value.frenchify()}`;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
throw new Error("unsupported nodeType: " + node.type);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const getInstruction = (identifiers) => {
|
|
94
|
+
const { nodeIds } = identifiers;
|
|
95
|
+
const node = NodeConstructor.fromIdentifiers(nodeIds);
|
|
96
|
+
return `On considère le programme Scratch ci-dessous :
|
|
97
|
+
|
|
98
|
+
<svg id="scratch">
|
|
99
|
+
quand @greenFlag est cliqué
|
|
100
|
+
mettre [x v] à ${getStrScratchblocks(node)}
|
|
101
|
+
</svg>
|
|
102
|
+
|
|
103
|
+
Quelle est la valeur de la variable $x$ à la fin de l'exécution du programme ?`;
|
|
104
|
+
};
|
|
105
|
+
const getFunctionForScratchProgram = (identifiers) => {
|
|
106
|
+
const { nodeIds } = identifiers;
|
|
107
|
+
return (_) => {
|
|
108
|
+
const outDict = {};
|
|
109
|
+
//convenience: store last step in -1
|
|
110
|
+
outDict[-1] = NodeConstructor.fromIdentifiers(nodeIds).evaluate();
|
|
111
|
+
return outDict;
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
const getAnswer = (identifiers) => {
|
|
115
|
+
const dictSteps = getFunctionForScratchProgram(identifiers)(identifiers);
|
|
116
|
+
return dictSteps[-1].frenchify();
|
|
117
|
+
};
|
|
118
|
+
const getHint = () => {
|
|
119
|
+
return `Calcule en commençant par les blocs les plus internes.`;
|
|
120
|
+
};
|
|
121
|
+
const getCorrection = (identifiers) => {
|
|
122
|
+
const { nodeIds } = identifiers;
|
|
123
|
+
const node = NodeConstructor.fromIdentifiers(nodeIds);
|
|
124
|
+
const nodeSimplified = node.simplify();
|
|
125
|
+
const texAnswer = nodeSimplified.toTex();
|
|
126
|
+
return `Le bloc d'opérations correspond à l'expression :
|
|
127
|
+
|
|
128
|
+
$$
|
|
129
|
+
${getTexWithParentheses(node)}
|
|
130
|
+
$$
|
|
131
|
+
|
|
132
|
+
On évalue l'expression en commençant par les parenthèses les plus intérieures.
|
|
133
|
+
|
|
134
|
+
La valeur de cette expression est $${texAnswer}$.
|
|
135
|
+
|
|
136
|
+
À la fin de l'exécution du programme, $x$ vaut $${texAnswer}$.`;
|
|
137
|
+
};
|
|
138
|
+
const getPropositions = (n, { answer, ...identifiers }) => {
|
|
139
|
+
const propositions = [];
|
|
140
|
+
addValidProp(propositions, answer);
|
|
141
|
+
const node = NodeConstructor.fromIdentifiers(identifiers.nodeIds);
|
|
142
|
+
{
|
|
143
|
+
let counter = -1;
|
|
144
|
+
while (counter < 10) {
|
|
145
|
+
counter++;
|
|
146
|
+
const nodeDeepShuffled = NodeShuffler.deepShuffle(node, {
|
|
147
|
+
nodeTypesToShuffle: [
|
|
148
|
+
"AddNode",
|
|
149
|
+
"SubstractNode",
|
|
150
|
+
"MultiplyNode",
|
|
151
|
+
"DivideNode",
|
|
152
|
+
],
|
|
153
|
+
nodeTypesNoFurther: [],
|
|
154
|
+
});
|
|
155
|
+
//add if no division by zero
|
|
156
|
+
try {
|
|
157
|
+
//check if explodes
|
|
158
|
+
{
|
|
159
|
+
nodeDeepShuffled.evaluate();
|
|
160
|
+
}
|
|
161
|
+
const identifiersWrong = Object.assign({}, identifiers, {
|
|
162
|
+
nodeIds: nodeDeepShuffled.toIdentifiers(),
|
|
163
|
+
});
|
|
164
|
+
tryToAddWrongProp(propositions, getAnswer(identifiersWrong));
|
|
165
|
+
}
|
|
166
|
+
catch (_) {
|
|
167
|
+
(() => { })();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
propWhile(propositions, n, () => {
|
|
172
|
+
tryToAddWrongProp(propositions, randint(-59, 60).frenchify());
|
|
173
|
+
});
|
|
174
|
+
return shuffleProps(propositions, n);
|
|
175
|
+
};
|
|
176
|
+
const getKeys = () => {
|
|
177
|
+
return [];
|
|
178
|
+
};
|
|
179
|
+
const isAnswerValid = (ans, { answer }) => {
|
|
180
|
+
try {
|
|
181
|
+
return numberVEA(ans, answer);
|
|
182
|
+
}
|
|
183
|
+
catch (err) {
|
|
184
|
+
return handleVEAError(err);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
const getScratchOperations1Question = () => {
|
|
188
|
+
const depth = randint(3, 5);
|
|
189
|
+
let node;
|
|
190
|
+
let counter = -1;
|
|
191
|
+
let isValid = false;
|
|
192
|
+
while (!isValid && counter < 100) {
|
|
193
|
+
counter++;
|
|
194
|
+
node = createRandomNode(depth);
|
|
195
|
+
try {
|
|
196
|
+
{
|
|
197
|
+
node.simplify(); //may explode
|
|
198
|
+
}
|
|
199
|
+
const value = node.evaluate(); //may explode
|
|
200
|
+
const isInteger = () => round(value, 0) === value;
|
|
201
|
+
const isNotTooBig = () => Math.abs(value) < 60;
|
|
202
|
+
isValid = isInteger() && isNotTooBig();
|
|
203
|
+
}
|
|
204
|
+
catch (_) {
|
|
205
|
+
(() => { })();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (!isValid) {
|
|
209
|
+
const nodeDefault = add(add(3, multiply(7, substract(3, 5))), 3);
|
|
210
|
+
node = nodeDefault;
|
|
211
|
+
}
|
|
212
|
+
const identifiers = {
|
|
213
|
+
nodeIds: node.toIdentifiers(),
|
|
214
|
+
};
|
|
215
|
+
return getQuestionFromIdentifiers(identifiers);
|
|
216
|
+
};
|
|
217
|
+
const getQuestionFromIdentifiers = (identifiers) => {
|
|
218
|
+
return {
|
|
219
|
+
answer: getAnswer(identifiers),
|
|
220
|
+
instruction: getInstruction(identifiers),
|
|
221
|
+
keys: getKeys(identifiers),
|
|
222
|
+
answerFormat: "tex",
|
|
223
|
+
identifiers,
|
|
224
|
+
hint: getHint(identifiers),
|
|
225
|
+
correction: getCorrection(identifiers),
|
|
226
|
+
};
|
|
227
|
+
};
|
|
228
|
+
export const scratchOperations1 = {
|
|
229
|
+
id: "scratchOperations1",
|
|
230
|
+
connector: "=",
|
|
231
|
+
label: "Calculer avec des priorités en Scratch",
|
|
232
|
+
isSingleStep: true,
|
|
233
|
+
generator: (nb, opts) => getDistinctQuestions(() => getScratchOperations1Question(opts), nb),
|
|
234
|
+
qcmTimer: 60,
|
|
235
|
+
freeTimer: 60,
|
|
236
|
+
getPropositions,
|
|
237
|
+
isAnswerValid,
|
|
238
|
+
subject: "Mathématiques",
|
|
239
|
+
getInstruction,
|
|
240
|
+
getHint,
|
|
241
|
+
getCorrection,
|
|
242
|
+
getAnswer,
|
|
243
|
+
getQuestionFromIdentifiers,
|
|
244
|
+
hasHintAndCorrection: true,
|
|
245
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Exercise } from "../../../exercises/exercise.js";
|
|
2
|
+
import { NodeIdentifiers } from "../../../tree/nodes/nodeConstructor.js";
|
|
3
|
+
type Identifiers = {
|
|
4
|
+
dictVars: Record<string, number>;
|
|
5
|
+
varNameDst: string;
|
|
6
|
+
nodeIds: NodeIdentifiers;
|
|
7
|
+
};
|
|
8
|
+
export declare const scratchOperations2: Exercise<Identifiers>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=scratchOperations2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scratchOperations2.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/scratch/scratchOperations2.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAeT,MAAM,6BAA6B,CAAC;AAOrC,OAAO,EAEL,eAAe,EAChB,MAAM,qCAAqC,CAAC;AA4I7C,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,eAAe,CAAC;CAC1B,CAAC;AAoOF,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,WAAW,CAkBpD,CAAC"}
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import { addValidProp, tryToAddWrongProp, propWhile, shuffleProps, } from "../../../exercises/exercise.js";
|
|
2
|
+
import { getDistinctQuestions } from "../../../exercises/utils/getDistinctQuestions.js";
|
|
3
|
+
import { numberVEA } from "../../../exercises/vea/numberVEA.js";
|
|
4
|
+
import { nodeBySubstitutingVar } from "../../../math/utils/functions/functionComposition.js";
|
|
5
|
+
import { randint } from "../../../math/utils/random/randint.js";
|
|
6
|
+
import { round } from "../../../math/utils/round.js";
|
|
7
|
+
import { NodeConstructor, } from "../../../tree/nodes/nodeConstructor.js";
|
|
8
|
+
import { isNumberNode, } from "../../../tree/nodes/numbers/numberNode.js";
|
|
9
|
+
import { add } from "../../../tree/nodes/operators/addNode.js";
|
|
10
|
+
import { divide } from "../../../tree/nodes/operators/divideNode.js";
|
|
11
|
+
import { multiply } from "../../../tree/nodes/operators/multiplyNode.js";
|
|
12
|
+
import { isOperatorNode, OperatorIds, } from "../../../tree/nodes/operators/operatorNode.js";
|
|
13
|
+
import { substract } from "../../../tree/nodes/operators/substractNode.js";
|
|
14
|
+
import { isVariableNode, } from "../../../tree/nodes/variables/variableNode.js";
|
|
15
|
+
import { NodeShuffler } from "../../../tree/utilities/nodeShuffler.js";
|
|
16
|
+
import { coinFlip } from "../../../utils/alea/coinFlip.js";
|
|
17
|
+
import { random } from "../../../utils/alea/random.js";
|
|
18
|
+
import { handleVEAError } from "../../../utils/errors/handleVEAError.js";
|
|
19
|
+
const getSetOfVarNames = (node) => {
|
|
20
|
+
if (isOperatorNode(node)) {
|
|
21
|
+
return new Set([node.leftChild, node.rightChild].flatMap((nodeChild) => [
|
|
22
|
+
...getSetOfVarNames(nodeChild),
|
|
23
|
+
]));
|
|
24
|
+
}
|
|
25
|
+
else if (isVariableNode(node)) {
|
|
26
|
+
return new Set([node.name]);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
return new Set([]);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const getSetOfNumbers = (node) => {
|
|
33
|
+
if (isOperatorNode(node)) {
|
|
34
|
+
return new Set([node.leftChild, node.rightChild].flatMap((nodeChild) => [
|
|
35
|
+
...getSetOfNumbers(nodeChild),
|
|
36
|
+
]));
|
|
37
|
+
}
|
|
38
|
+
else if (isNumberNode(node)) {
|
|
39
|
+
return new Set([node.value]);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
return new Set([]);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const createRandomNode = (depth, varNodes) => {
|
|
46
|
+
let nodeX;
|
|
47
|
+
let nodeY;
|
|
48
|
+
if (depth === 0) {
|
|
49
|
+
if (coinFlip()) {
|
|
50
|
+
return random(varNodes);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
return randint(1, 10).toTree();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
const depthLeft = randint(0, depth);
|
|
58
|
+
const depthRight = depth - 1 - depthLeft;
|
|
59
|
+
[nodeX, nodeY] = [depthLeft, depthRight].map((depthChild) => createRandomNode(depthChild, varNodes));
|
|
60
|
+
}
|
|
61
|
+
return random([add, substract, multiply, divide])(nodeX, nodeY);
|
|
62
|
+
};
|
|
63
|
+
const getStrScratchblocks = (node) => {
|
|
64
|
+
if (isOperatorNode(node)) {
|
|
65
|
+
const nodeOperator = node;
|
|
66
|
+
const strScratchOperator = (() => {
|
|
67
|
+
switch (nodeOperator.id) {
|
|
68
|
+
case OperatorIds.add:
|
|
69
|
+
return "+";
|
|
70
|
+
case OperatorIds.substract:
|
|
71
|
+
return "-";
|
|
72
|
+
case OperatorIds.multiply:
|
|
73
|
+
return "*";
|
|
74
|
+
case OperatorIds.divide:
|
|
75
|
+
return "/";
|
|
76
|
+
default:
|
|
77
|
+
throw new Error("unsupported id: " + nodeOperator.id);
|
|
78
|
+
}
|
|
79
|
+
})();
|
|
80
|
+
const [strLeft, strRight] = [
|
|
81
|
+
nodeOperator.leftChild,
|
|
82
|
+
nodeOperator.rightChild,
|
|
83
|
+
].map((nodeChild) => {
|
|
84
|
+
return getStrScratchblocks(nodeChild);
|
|
85
|
+
});
|
|
86
|
+
return `(${strLeft}${strScratchOperator}${strRight})`;
|
|
87
|
+
}
|
|
88
|
+
else if (isNumberNode(node)) {
|
|
89
|
+
return `(${node.value.frenchify()})`;
|
|
90
|
+
}
|
|
91
|
+
else if (isVariableNode(node)) {
|
|
92
|
+
return `(${node.name})`;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
throw new Error("unsupported nodeType: " + node.type);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const getTexWithParentheses = (node) => {
|
|
99
|
+
if (isOperatorNode(node)) {
|
|
100
|
+
const nodeOperator = node;
|
|
101
|
+
const strScratchOperator = (() => {
|
|
102
|
+
switch (nodeOperator.id) {
|
|
103
|
+
case OperatorIds.add:
|
|
104
|
+
return "+";
|
|
105
|
+
case OperatorIds.substract:
|
|
106
|
+
return "-";
|
|
107
|
+
case OperatorIds.multiply:
|
|
108
|
+
return "\\times";
|
|
109
|
+
case OperatorIds.divide:
|
|
110
|
+
return "\\div";
|
|
111
|
+
default:
|
|
112
|
+
throw new Error("unsupported id: " + nodeOperator.id);
|
|
113
|
+
}
|
|
114
|
+
})();
|
|
115
|
+
const [strLeft, strRight] = [
|
|
116
|
+
nodeOperator.leftChild,
|
|
117
|
+
nodeOperator.rightChild,
|
|
118
|
+
].map((nodeChild) => {
|
|
119
|
+
return getTexWithParentheses(nodeChild);
|
|
120
|
+
});
|
|
121
|
+
return `\\left(${strLeft} \\ ${strScratchOperator} \\ ${strRight}\\right)`;
|
|
122
|
+
}
|
|
123
|
+
else if (isNumberNode(node)) {
|
|
124
|
+
return `${node.value.frenchify()}`;
|
|
125
|
+
}
|
|
126
|
+
else if (isVariableNode(node)) {
|
|
127
|
+
return `${node.name}`;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
throw new Error("unsupported nodeType: " + node.type);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
const getInstruction = (identifiers) => {
|
|
134
|
+
const { dictVars, varNameDst, nodeIds } = identifiers;
|
|
135
|
+
const node = NodeConstructor.fromIdentifiers(nodeIds);
|
|
136
|
+
return `On considère le programme Scratch ci-dessous :
|
|
137
|
+
|
|
138
|
+
<svg id="scratch">
|
|
139
|
+
quand @greenFlag est cliqué
|
|
140
|
+
${Object.entries(dictVars).map(([varName, value]) => `mettre [${varName} v] à (${value.frenchify()})`).join(`
|
|
141
|
+
`)}
|
|
142
|
+
mettre [${varNameDst} v] à ${getStrScratchblocks(node)}
|
|
143
|
+
</svg>
|
|
144
|
+
|
|
145
|
+
Quelle est la valeur de la variable $${varNameDst}$ à la fin de l'exécution du programme ?`;
|
|
146
|
+
};
|
|
147
|
+
const getFunctionForScratchProgram = (identifiers) => {
|
|
148
|
+
const { dictVars, nodeIds } = identifiers;
|
|
149
|
+
return (_) => {
|
|
150
|
+
const outDict = {};
|
|
151
|
+
//convenience: store last step in -1
|
|
152
|
+
outDict[-1] = NodeConstructor.fromIdentifiers(nodeIds).evaluate(dictVars);
|
|
153
|
+
return outDict;
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
const getAnswer = (identifiers) => {
|
|
157
|
+
const dictSteps = getFunctionForScratchProgram(identifiers)(identifiers);
|
|
158
|
+
return dictSteps[-1].frenchify();
|
|
159
|
+
};
|
|
160
|
+
const getHint = () => {
|
|
161
|
+
return `Calcule en commençant par les blocs les plus internes. Substitue chaque variable par sa valeur pour faire le calcul.`;
|
|
162
|
+
};
|
|
163
|
+
const getCorrection = (identifiers) => {
|
|
164
|
+
const { dictVars, varNameDst, nodeIds } = identifiers;
|
|
165
|
+
const node = NodeConstructor.fromIdentifiers(nodeIds);
|
|
166
|
+
const nodeSubstituted = Object.entries(dictVars).reduce((acc, [varName, value]) => {
|
|
167
|
+
const nodeBySub = nodeBySubstitutingVar(acc, value.toTree(), varName.toTree());
|
|
168
|
+
return nodeBySub;
|
|
169
|
+
}, node);
|
|
170
|
+
const nodeSimplified = nodeSubstituted.simplify();
|
|
171
|
+
const texAnswer = nodeSimplified.toTex();
|
|
172
|
+
return `Le bloc d'opérations correspond à l'expression :
|
|
173
|
+
|
|
174
|
+
$$
|
|
175
|
+
${getTexWithParentheses(node)}
|
|
176
|
+
$$
|
|
177
|
+
|
|
178
|
+
Après substitution des variables par leur valeur, on a :
|
|
179
|
+
|
|
180
|
+
$$
|
|
181
|
+
${getTexWithParentheses(nodeSubstituted)}
|
|
182
|
+
$$
|
|
183
|
+
|
|
184
|
+
On évalue l'expression en commençant par les parenthèses les plus intérieures.
|
|
185
|
+
|
|
186
|
+
La valeur de cette expression est $${texAnswer}$.
|
|
187
|
+
|
|
188
|
+
À la fin de l'exécution du programme, $${varNameDst}$ vaut $${texAnswer}$.`;
|
|
189
|
+
};
|
|
190
|
+
const getPropositions = (n, { answer, ...identifiers }) => {
|
|
191
|
+
const propositions = [];
|
|
192
|
+
addValidProp(propositions, answer);
|
|
193
|
+
const node = NodeConstructor.fromIdentifiers(identifiers.nodeIds);
|
|
194
|
+
{
|
|
195
|
+
let counter = -1;
|
|
196
|
+
while (counter < 10) {
|
|
197
|
+
counter++;
|
|
198
|
+
const nodeDeepShuffled = NodeShuffler.deepShuffle(node, {
|
|
199
|
+
nodeTypesToShuffle: [
|
|
200
|
+
"AddNode",
|
|
201
|
+
"SubstractNode",
|
|
202
|
+
"MultiplyNode",
|
|
203
|
+
"DivideNode",
|
|
204
|
+
],
|
|
205
|
+
nodeTypesNoFurther: [],
|
|
206
|
+
});
|
|
207
|
+
//add if no division by zero
|
|
208
|
+
try {
|
|
209
|
+
//check if explodes
|
|
210
|
+
{
|
|
211
|
+
nodeDeepShuffled.evaluate();
|
|
212
|
+
}
|
|
213
|
+
const identifiersWrong = Object.assign({}, identifiers, {
|
|
214
|
+
nodeIds: nodeDeepShuffled.toIdentifiers(),
|
|
215
|
+
});
|
|
216
|
+
tryToAddWrongProp(propositions, getAnswer(identifiersWrong));
|
|
217
|
+
}
|
|
218
|
+
catch (_) {
|
|
219
|
+
(() => { })();
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
propWhile(propositions, n, () => {
|
|
224
|
+
tryToAddWrongProp(propositions, randint(-59, 60).frenchify());
|
|
225
|
+
});
|
|
226
|
+
return shuffleProps(propositions, n);
|
|
227
|
+
};
|
|
228
|
+
const getKeys = () => {
|
|
229
|
+
return ["x", "y", "z"];
|
|
230
|
+
};
|
|
231
|
+
const isAnswerValid = (ans, { answer }) => {
|
|
232
|
+
try {
|
|
233
|
+
return numberVEA(ans, answer);
|
|
234
|
+
}
|
|
235
|
+
catch (err) {
|
|
236
|
+
return handleVEAError(err);
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
const getScratchOperations2Question = () => {
|
|
240
|
+
const varNames = ["x", "y", "z"];
|
|
241
|
+
const indexDst = randint(0, varNames.length);
|
|
242
|
+
let dictVars = Object.fromEntries(varNames
|
|
243
|
+
.filter((_, i) => i !== indexDst)
|
|
244
|
+
.map((varName) => [varName, randint(1, 10)]));
|
|
245
|
+
const depth = randint(3, 5);
|
|
246
|
+
let node;
|
|
247
|
+
let counter = -1;
|
|
248
|
+
let isValid = false;
|
|
249
|
+
while (!isValid && counter < 100) {
|
|
250
|
+
counter++;
|
|
251
|
+
node = createRandomNode(depth, [...Object.keys(dictVars)].map((varName) => varName.toTree()));
|
|
252
|
+
const isContainingVars = () => [...getSetOfVarNames(node)].length > 0;
|
|
253
|
+
const isContainingNumbers = () => [...getSetOfNumbers(node)].length > 0;
|
|
254
|
+
if (isContainingVars() && isContainingNumbers()) {
|
|
255
|
+
try {
|
|
256
|
+
//sometimes, doing computation step by step can prevent algebraic simplification which would allow complete evaluation
|
|
257
|
+
//expl: 9 div (1 div y-y)
|
|
258
|
+
{
|
|
259
|
+
const nodeSubstituted = Object.entries(dictVars).reduce((acc, [varName, value]) => {
|
|
260
|
+
const nodeBySub = nodeBySubstitutingVar(acc, value.toTree(), varName.toTree());
|
|
261
|
+
return nodeBySub;
|
|
262
|
+
}, node);
|
|
263
|
+
nodeSubstituted.simplify(); //may explode
|
|
264
|
+
}
|
|
265
|
+
const value = node.evaluate(dictVars); //may explode
|
|
266
|
+
const isInteger = () => round(value, 0) === value;
|
|
267
|
+
const isNotTooBig = () => Math.abs(value) < 60;
|
|
268
|
+
isValid = isInteger() && isNotTooBig();
|
|
269
|
+
}
|
|
270
|
+
catch (_) {
|
|
271
|
+
(() => { })();
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
isValid = false;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (!isValid) {
|
|
279
|
+
const [nodeA, nodeB] = [1, 8].map((v) => v.toTree());
|
|
280
|
+
dictVars = Object.fromEntries(varNames
|
|
281
|
+
.filter((_, i) => i !== indexDst)
|
|
282
|
+
.map((varName, k) => [
|
|
283
|
+
varName,
|
|
284
|
+
[nodeA, nodeB].map((node) => node.value)[k],
|
|
285
|
+
]));
|
|
286
|
+
const nodeDefault = add(add(nodeB, multiply(7, substract(3, nodeA))), nodeA);
|
|
287
|
+
node = nodeDefault;
|
|
288
|
+
}
|
|
289
|
+
const identifiers = {
|
|
290
|
+
dictVars,
|
|
291
|
+
varNameDst: varNames[indexDst],
|
|
292
|
+
nodeIds: node.toIdentifiers(),
|
|
293
|
+
};
|
|
294
|
+
return getQuestionFromIdentifiers(identifiers);
|
|
295
|
+
};
|
|
296
|
+
const getQuestionFromIdentifiers = (identifiers) => {
|
|
297
|
+
return {
|
|
298
|
+
answer: getAnswer(identifiers),
|
|
299
|
+
instruction: getInstruction(identifiers),
|
|
300
|
+
keys: getKeys(identifiers),
|
|
301
|
+
answerFormat: "tex",
|
|
302
|
+
identifiers,
|
|
303
|
+
hint: getHint(identifiers),
|
|
304
|
+
correction: getCorrection(identifiers),
|
|
305
|
+
};
|
|
306
|
+
};
|
|
307
|
+
export const scratchOperations2 = {
|
|
308
|
+
id: "scratchOperations2",
|
|
309
|
+
connector: "=",
|
|
310
|
+
label: "Calculer avec des priorités et des variables en Scratch",
|
|
311
|
+
isSingleStep: true,
|
|
312
|
+
generator: (nb, opts) => getDistinctQuestions(() => getScratchOperations2Question(opts), nb),
|
|
313
|
+
qcmTimer: 60,
|
|
314
|
+
freeTimer: 60,
|
|
315
|
+
getPropositions,
|
|
316
|
+
isAnswerValid,
|
|
317
|
+
subject: "Mathématiques",
|
|
318
|
+
getInstruction,
|
|
319
|
+
getHint,
|
|
320
|
+
getCorrection,
|
|
321
|
+
getAnswer,
|
|
322
|
+
getQuestionFromIdentifiers,
|
|
323
|
+
hasHintAndCorrection: true,
|
|
324
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scratchPrintXY.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/scratch/scratchPrintXY.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,6BAA6B,CAAC;AAKrC,KAAK,WAAW,GAAG;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAmMF,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,WAAW,CAmBhD,CAAC"}
|