math-exercises 3.0.215 → 3.0.216

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 (114) hide show
  1. package/lib/exercises/math/arithmetic/whichDayInXDays.d.ts.map +1 -1
  2. package/lib/exercises/math/arithmetic/whichDayInXDays.js +2 -1
  3. package/lib/exercises/math/complex/unitRoots/giveOneSolutionToComplexPowNEqualsOne.js +1 -1
  4. package/lib/exercises/math/conversion/clock/index.d.ts +0 -1
  5. package/lib/exercises/math/conversion/clock/index.d.ts.map +1 -1
  6. package/lib/exercises/math/conversion/clock/index.js +1 -1
  7. package/lib/exercises/math/graphs/adjacentMatrixPath.d.ts +10 -0
  8. package/lib/exercises/math/graphs/adjacentMatrixPath.d.ts.map +1 -0
  9. package/lib/exercises/math/graphs/adjacentMatrixPath.js +89 -0
  10. package/lib/exercises/math/graphs/edgesNumberFromSummitsDegrees.d.ts +7 -0
  11. package/lib/exercises/math/graphs/edgesNumberFromSummitsDegrees.d.ts.map +1 -0
  12. package/lib/exercises/math/graphs/edgesNumberFromSummitsDegrees.js +98 -0
  13. package/lib/exercises/math/graphs/eulerianChainFromAdjacentMatrix.d.ts +8 -0
  14. package/lib/exercises/math/graphs/eulerianChainFromAdjacentMatrix.d.ts.map +1 -0
  15. package/lib/exercises/math/graphs/eulerianChainFromAdjacentMatrix.js +96 -0
  16. package/lib/exercises/math/graphs/graphsChainOrPathOfLengthN.d.ts +15 -0
  17. package/lib/exercises/math/graphs/graphsChainOrPathOfLengthN.d.ts.map +1 -0
  18. package/lib/exercises/math/graphs/graphsChainOrPathOfLengthN.js +262 -0
  19. package/lib/exercises/math/graphs/graphsCheckIsConnectedUndirectedGraph.d.ts +11 -0
  20. package/lib/exercises/math/graphs/graphsCheckIsConnectedUndirectedGraph.d.ts.map +1 -0
  21. package/lib/exercises/math/graphs/graphsCheckIsConnectedUndirectedGraph.js +178 -0
  22. package/lib/exercises/math/graphs/graphsCheckIsSameGraph.d.ts +19 -0
  23. package/lib/exercises/math/graphs/graphsCheckIsSameGraph.d.ts.map +1 -0
  24. package/lib/exercises/math/graphs/graphsCheckIsSameGraph.js +301 -0
  25. package/lib/exercises/math/graphs/graphsCheckIsVerticesAdjacent.d.ts +16 -0
  26. package/lib/exercises/math/graphs/graphsCheckIsVerticesAdjacent.d.ts.map +1 -0
  27. package/lib/exercises/math/graphs/graphsCheckIsVerticesAdjacent.js +207 -0
  28. package/lib/exercises/math/graphs/graphsDegreeOfVertex.d.ts +15 -0
  29. package/lib/exercises/math/graphs/graphsDegreeOfVertex.d.ts.map +1 -0
  30. package/lib/exercises/math/graphs/graphsDegreeOfVertex.js +232 -0
  31. package/lib/exercises/math/graphs/graphsOrderOfGraph.d.ts +14 -0
  32. package/lib/exercises/math/graphs/graphsOrderOfGraph.d.ts.map +1 -0
  33. package/lib/exercises/math/graphs/graphsOrderOfGraph.js +222 -0
  34. package/lib/exercises/math/graphs/index.d.ts +10 -0
  35. package/lib/exercises/math/graphs/index.d.ts.map +1 -0
  36. package/lib/exercises/math/graphs/index.js +9 -0
  37. package/lib/exercises/math/index.d.ts +1 -0
  38. package/lib/exercises/math/index.d.ts.map +1 -1
  39. package/lib/exercises/math/index.js +1 -0
  40. package/lib/exercises/math/matrices/areMatricesInverse.d.ts +9 -0
  41. package/lib/exercises/math/matrices/areMatricesInverse.d.ts.map +1 -0
  42. package/lib/exercises/math/matrices/areMatricesInverse.js +106 -0
  43. package/lib/exercises/math/matrices/computeFixedMatrixInRecurrenceSequence.d.ts +9 -0
  44. package/lib/exercises/math/matrices/computeFixedMatrixInRecurrenceSequence.d.ts.map +1 -0
  45. package/lib/exercises/math/matrices/computeFixedMatrixInRecurrenceSequence.js +144 -0
  46. package/lib/exercises/math/matrices/findInversedMatrixFromSystem.d.ts +8 -0
  47. package/lib/exercises/math/matrices/findInversedMatrixFromSystem.d.ts.map +1 -0
  48. package/lib/exercises/math/matrices/findInversedMatrixFromSystem.js +148 -0
  49. package/lib/exercises/math/matrices/index.d.ts +12 -0
  50. package/lib/exercises/math/matrices/index.d.ts.map +1 -1
  51. package/lib/exercises/math/matrices/index.js +12 -0
  52. package/lib/exercises/math/matrices/isMatrixTransitionMatrix.d.ts +8 -0
  53. package/lib/exercises/math/matrices/isMatrixTransitionMatrix.d.ts.map +1 -0
  54. package/lib/exercises/math/matrices/isMatrixTransitionMatrix.js +132 -0
  55. package/lib/exercises/math/matrices/matrixBuildMatrixFromCoefficients.d.ts +8 -0
  56. package/lib/exercises/math/matrices/matrixBuildMatrixFromCoefficients.d.ts.map +1 -0
  57. package/lib/exercises/math/matrices/matrixBuildMatrixFromCoefficients.js +152 -0
  58. package/lib/exercises/math/matrices/matrixCheckIsSymmetrical.d.ts +8 -0
  59. package/lib/exercises/math/matrices/matrixCheckIsSymmetrical.d.ts.map +1 -0
  60. package/lib/exercises/math/matrices/matrixCheckIsSymmetrical.js +155 -0
  61. package/lib/exercises/math/matrices/matrixComputeDetOfMat2.d.ts +8 -0
  62. package/lib/exercises/math/matrices/matrixComputeDetOfMat2.d.ts.map +1 -0
  63. package/lib/exercises/math/matrices/matrixComputeDetOfMat2.js +142 -0
  64. package/lib/exercises/math/matrices/matrixComputeInverseOfMat2.d.ts +8 -0
  65. package/lib/exercises/math/matrices/matrixComputeInverseOfMat2.d.ts.map +1 -0
  66. package/lib/exercises/math/matrices/matrixComputeInverseOfMat2.js +237 -0
  67. package/lib/exercises/math/matrices/matrixComputeLinearCombination.d.ts +15 -0
  68. package/lib/exercises/math/matrices/matrixComputeLinearCombination.d.ts.map +1 -0
  69. package/lib/exercises/math/matrices/matrixComputeLinearCombination.js +232 -0
  70. package/lib/exercises/math/matrices/matrixComputePower.d.ts +12 -0
  71. package/lib/exercises/math/matrices/matrixComputePower.d.ts.map +1 -0
  72. package/lib/exercises/math/matrices/matrixComputePower.js +230 -0
  73. package/lib/exercises/math/matrices/matrixComputeProduct.d.ts +9 -0
  74. package/lib/exercises/math/matrices/matrixComputeProduct.d.ts.map +1 -0
  75. package/lib/exercises/math/matrices/matrixComputeProduct.js +178 -0
  76. package/lib/exercises/math/matrices/writeMatrixAssociatedToSystem.d.ts +8 -0
  77. package/lib/exercises/math/matrices/writeMatrixAssociatedToSystem.d.ts.map +1 -0
  78. package/lib/exercises/math/matrices/writeMatrixAssociatedToSystem.js +105 -0
  79. package/lib/exercises/vea/matrixVEA.d.ts +2 -0
  80. package/lib/exercises/vea/matrixVEA.d.ts.map +1 -0
  81. package/lib/exercises/vea/matrixVEA.js +1 -0
  82. package/lib/index.d.ts +86 -13
  83. package/lib/index.d.ts.map +1 -1
  84. package/lib/math/geometry/point.d.ts.map +1 -1
  85. package/lib/math/geometry/point.js +3 -1
  86. package/lib/math/graphs/graph.d.ts +43 -0
  87. package/lib/math/graphs/graph.d.ts.map +1 -0
  88. package/lib/math/graphs/graph.js +391 -0
  89. package/lib/math/matrices/matrix.d.ts +42 -3
  90. package/lib/math/matrices/matrix.d.ts.map +1 -1
  91. package/lib/math/matrices/matrix.js +173 -7
  92. package/lib/math/matrices/parseMatrix.d.ts +3 -0
  93. package/lib/math/matrices/parseMatrix.d.ts.map +1 -0
  94. package/lib/math/matrices/parseMatrix.js +22 -0
  95. package/lib/math/systems/generalSystem.d.ts +2 -0
  96. package/lib/math/systems/generalSystem.d.ts.map +1 -1
  97. package/lib/math/systems/generalSystem.js +5 -0
  98. package/lib/math/utils/graphs/graphRenderer.d.ts +25 -0
  99. package/lib/math/utils/graphs/graphRenderer.d.ts.map +1 -0
  100. package/lib/math/utils/graphs/graphRenderer.js +123 -0
  101. package/lib/playground.d.ts +6 -1
  102. package/lib/playground.d.ts.map +1 -1
  103. package/lib/playground.js +6 -5
  104. package/lib/tree/parsers/latexParser.d.ts +1 -1
  105. package/lib/tree/utilities/nodeSimplifier.d.ts +1 -1
  106. package/lib/types/keyIds.d.ts +2 -0
  107. package/lib/types/keyIds.d.ts.map +1 -1
  108. package/lib/utils/arrays/arrayChunks.d.ts +9 -0
  109. package/lib/utils/arrays/arrayChunks.d.ts.map +1 -0
  110. package/lib/utils/arrays/arrayChunks.js +34 -0
  111. package/lib/utils/strings/ordinalSuffixed.d.ts +2 -0
  112. package/lib/utils/strings/ordinalSuffixed.d.ts.map +1 -0
  113. package/lib/utils/strings/ordinalSuffixed.js +5 -0
  114. package/package.json +7 -1
@@ -0,0 +1,207 @@
1
+ import { addValidProp, tryToAddWrongProp, GeneratorOptionTarget, GeneratorOptionType, } from "../../../exercises/exercise.js";
2
+ import { getDistinctQuestions } from "../../../exercises/utils/getDistinctQuestions.js";
3
+ import { defaultArrayedOptsWhereNeeded } from "../../../exercises/utils/options/arrayedOptions.js";
4
+ import { greenMain } from "../../../geogebra/colors.js";
5
+ import { GeogebraConstructor } from "../../../geogebra/geogebraConstructor.js";
6
+ import { Point } from "../../../math/geometry/point.js";
7
+ import { GraphConstructor } from "../../../math/graphs/graph.js";
8
+ import { GraphRenderer, } from "../../../math/utils/graphs/graphRenderer.js";
9
+ import { randint } from "../../../math/utils/random/randint.js";
10
+ import { coinFlip } from "../../../utils/alea/coinFlip.js";
11
+ import { random } from "../../../utils/alea/random.js";
12
+ import { shuffle } from "../../../utils/alea/shuffle.js";
13
+ const getHydrated = (identifiers) => {
14
+ const { graphIds, nameVertex1, nameVertex2 } = identifiers;
15
+ const graph = GraphConstructor.fromIdentifiers(graphIds);
16
+ const dictConnections = graph.dictConnections();
17
+ const isAdjacent = dictConnections[nameVertex1][nameVertex2] ||
18
+ dictConnections[nameVertex2][nameVertex1];
19
+ return {
20
+ graph,
21
+ isAdjacent,
22
+ };
23
+ };
24
+ const getInstruction = (identifiers) => {
25
+ const { nameVertex1, nameVertex2 } = identifiers;
26
+ return `Un graphe est représenté ci-dessous.
27
+ Les sommets $${nameVertex1}$ et $${nameVertex2}$ sont-ils adjacents ?`;
28
+ };
29
+ const getAnswer = (identifiers) => {
30
+ const { isAdjacent } = getHydrated(identifiers);
31
+ return isAdjacent ? "Oui" : "Non";
32
+ };
33
+ const getHint = () => {
34
+ return `Deux sommets sont adjacents si et seulement si ils sont reliés par une arête.`;
35
+ };
36
+ const getCorrection = (identifiers) => {
37
+ const { nameVertex1, nameVertex2 } = identifiers;
38
+ const { isAdjacent } = getHydrated(identifiers);
39
+ if (isAdjacent) {
40
+ return `Les sommets $${nameVertex1}$ et $${nameVertex2}$ sont reliés par au moins une arête.
41
+ Ils sont adjacents.`;
42
+ }
43
+ else {
44
+ return `Les sommets $${nameVertex1}$ et $${nameVertex2}$ ne sont pas reliés par une arête.
45
+ Ils ne sont pas adjacents.`;
46
+ }
47
+ };
48
+ const getCorrectionGGBOptions = (identifiers) => {
49
+ const { graphNodes, graphEdges, nameVertex1, nameVertex2 } = identifiers;
50
+ const { graph } = getHydrated(identifiers);
51
+ const arrPoint = graphNodes.map(({ label, x, y }) => new Point(label, x, y));
52
+ const pointCommands = arrPoint.flatMap((point) => point.toGGBCommand({
53
+ isFixed: false,
54
+ isSelectionnable: true,
55
+ showLabel: true,
56
+ style: 0,
57
+ size: 8,
58
+ color: point.name === nameVertex1 || point.name === nameVertex2
59
+ ? greenMain
60
+ : "#000000",
61
+ }));
62
+ const edgeCommands = graphEdges.flatMap((e, i) => {
63
+ return [
64
+ graph.isDirected
65
+ ? `edge${i + 1} = Vector(${e.from}, ${e.to})`
66
+ : `edge${i + 1} = Segment(${e.from}, ${e.to})`,
67
+ ...((e.from === nameVertex1 && e.to === nameVertex2) ||
68
+ (e.from === nameVertex2 && e.to === nameVertex1)
69
+ ? [`SetColor(edge${i + 1}, "${greenMain}")`]
70
+ : []),
71
+ ];
72
+ });
73
+ const ggb = new GeogebraConstructor({
74
+ commands: [...pointCommands, ...edgeCommands],
75
+ fontSize: 16,
76
+ hideAxes: true,
77
+ hideGrid: true,
78
+ });
79
+ return ggb.getOptions({
80
+ coords: ggb.getCoordsForPoints(arrPoint),
81
+ });
82
+ };
83
+ const getGGBOptions = (identifiers) => {
84
+ const { graphNodes, graphEdges } = identifiers;
85
+ const { graph } = getHydrated(identifiers);
86
+ const arrPoint = graphNodes.map(({ label, x, y }) => new Point(label, x, y));
87
+ const pointCommands = arrPoint.flatMap((point) => point.toGGBCommand({
88
+ isFixed: false,
89
+ isSelectionnable: true,
90
+ showLabel: true,
91
+ style: 0,
92
+ size: 8,
93
+ }));
94
+ const edgeCommands = graphEdges.map((e, i) => graph.isDirected
95
+ ? `v${i + 1} = Vector(${e.from}, ${e.to})`
96
+ : `s${i + 1} = Segment(${e.from}, ${e.to})`);
97
+ const arrGGBCommandForGraph = [...pointCommands, ...edgeCommands];
98
+ const ggb = new GeogebraConstructor({
99
+ commands: [...arrGGBCommandForGraph],
100
+ fontSize: 16,
101
+ hideAxes: true,
102
+ hideGrid: true,
103
+ });
104
+ return ggb.getOptions({
105
+ coords: ggb.getCoordsForPoints(arrPoint),
106
+ });
107
+ };
108
+ const getPropositions = (_, { answer }) => {
109
+ const propositions = [];
110
+ ["Oui", "Non"].forEach((str) => {
111
+ if (str === answer) {
112
+ addValidProp(propositions, str, "raw");
113
+ }
114
+ else {
115
+ tryToAddWrongProp(propositions, str, "raw");
116
+ }
117
+ });
118
+ return propositions;
119
+ };
120
+ const createRandomIdentifiers = (isDirected) => {
121
+ const nbVertices = randint(5, 10);
122
+ const isSimple = true;
123
+ const minDensity = (() => {
124
+ switch (nbVertices) {
125
+ case 5:
126
+ return isDirected ? 0.4 : 0.62;
127
+ case 6:
128
+ return isDirected ? 0.35 : 0.57;
129
+ case 7:
130
+ return isDirected ? 0.3 : 0.52;
131
+ case 8:
132
+ return isDirected ? 0.27 : 0.37;
133
+ case 9:
134
+ return isDirected ? 0.24 : 0.32;
135
+ }
136
+ })();
137
+ const graph = GraphConstructor.random(nbVertices, isSimple, isDirected, minDensity, "ABCDEFGHIJKLM".split(""), true);
138
+ const { nodes: graphNodes, edges: graphEdges } = GraphRenderer.renderToNodesAndEdges(graph);
139
+ const [nameVertex1, nameVertex2] = shuffle((() => {
140
+ const isAdjacent = coinFlip();
141
+ const arrConnection = graph.arrConnection();
142
+ return random(arrConnection
143
+ .filter(([_nameVertexStart, _nameVertexEnd, isConnection]) => isConnection === isAdjacent)
144
+ .map(([nameVertexStart, nameVertexEnd, _]) => [
145
+ nameVertexStart,
146
+ nameVertexEnd,
147
+ ]));
148
+ })());
149
+ const identifiers = {
150
+ graphIds: graph.toIdentifiers(),
151
+ nameVertex1,
152
+ nameVertex2,
153
+ graphNodes,
154
+ graphEdges,
155
+ };
156
+ return identifiers;
157
+ };
158
+ const getGraphsCheckIsVerticesAdjacentQuestion = (optsIn) => {
159
+ const arrayedOpts = defaultArrayedOptsWhereNeeded(optsIn, arrayedOptsDefault);
160
+ const opts = {
161
+ graphType: random(arrayedOpts.graphType),
162
+ };
163
+ const isDirected = opts.graphType === "orienté";
164
+ const identifiers = createRandomIdentifiers(isDirected);
165
+ return getQuestionFromIdentifiers(identifiers);
166
+ };
167
+ const getQuestionFromIdentifiers = (identifiers, opts) => {
168
+ const question = {
169
+ answer: getAnswer(identifiers, opts),
170
+ instruction: getInstruction(identifiers, opts),
171
+ answerFormat: "raw",
172
+ identifiers,
173
+ hint: getHint(identifiers, opts),
174
+ correction: getCorrection(identifiers, opts),
175
+ correctionGgbOptions: getCorrectionGGBOptions(identifiers, opts),
176
+ ggbOptions: getGGBOptions(identifiers, opts),
177
+ };
178
+ return question;
179
+ };
180
+ const arrayedOptsDefault = {
181
+ graphType: ["non orienté"],
182
+ };
183
+ const options = [
184
+ {
185
+ id: "graphType",
186
+ label: "Types de graphes",
187
+ target: GeneratorOptionTarget.generation,
188
+ type: GeneratorOptionType.multiselect,
189
+ values: ["non orienté", "orienté"],
190
+ defaultValue: arrayedOptsDefault.graphType,
191
+ },
192
+ ];
193
+ export const graphsCheckIsVerticesAdjacent = {
194
+ id: "graphsCheckIsVerticesAdjacent",
195
+ label: "Déterminer si deux sommets sont adjacents",
196
+ isSingleStep: true,
197
+ generator: (nb, opts) => getDistinctQuestions(() => getGraphsCheckIsVerticesAdjacentQuestion(opts), nb),
198
+ options,
199
+ qcmTimer: 60,
200
+ freeTimer: 60,
201
+ getPropositions,
202
+ subject: "Mathématiques",
203
+ getQuestionFromIdentifiers,
204
+ hasHintAndCorrection: true,
205
+ hasGeogebra: true,
206
+ answerType: "QCU",
207
+ };
@@ -0,0 +1,15 @@
1
+ import { Exercise } from "../../../exercises/exercise.js";
2
+ import { GraphIdentifiers } from "../../../math/graphs/graph.js";
3
+ import { GraphEdge, GraphNode } from "../../../math/utils/graphs/graphRenderer.js";
4
+ type Identifiers = {
5
+ graphIds: GraphIdentifiers;
6
+ indexAsked: number;
7
+ graphNodes: GraphNode[];
8
+ graphEdges: GraphEdge[];
9
+ };
10
+ type Options = {
11
+ graphType: string;
12
+ };
13
+ export declare const graphsDegreeOfVertex: Exercise<Identifiers, Options>;
14
+ export {};
15
+ //# sourceMappingURL=graphsDegreeOfVertex.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphsDegreeOfVertex.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/graphs/graphsDegreeOfVertex.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAoBT,MAAM,6BAA6B,CAAC;AAMrC,OAAO,EAAoB,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAChF,OAAO,EACL,SAAS,EACT,SAAS,EAEV,MAAM,0CAA0C,CAAC;AASlD,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IAGnB,UAAU,EAAE,SAAS,EAAE,CAAC;IACxB,UAAU,EAAE,SAAS,EAAE,CAAC;CACzB,CAAC;AAmQF,KAAK,OAAO,GAAG;IACb,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAsBF,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,WAAW,EAAE,OAAO,CAe/D,CAAC"}
@@ -0,0 +1,232 @@
1
+ import { addValidProp, shuffleProps, tryToAddWrongProp, propWhile, GeneratorOptionTarget, GeneratorOptionType, } from "../../../exercises/exercise.js";
2
+ import { getDistinctQuestions } from "../../../exercises/utils/getDistinctQuestions.js";
3
+ import { defaultArrayedOptsWhereNeeded } from "../../../exercises/utils/options/arrayedOptions.js";
4
+ import { greenMain } from "../../../geogebra/colors.js";
5
+ import { GeogebraConstructor } from "../../../geogebra/geogebraConstructor.js";
6
+ import { Point } from "../../../math/geometry/point.js";
7
+ import { GraphConstructor } from "../../../math/graphs/graph.js";
8
+ import { GraphRenderer, } from "../../../math/utils/graphs/graphRenderer.js";
9
+ import { randint } from "../../../math/utils/random/randint.js";
10
+ import { parseAlgebraic } from "../../../tree/parsers/latexParser.js";
11
+ import { NodeComparator } from "../../../tree/utilities/nodeComparator.js";
12
+ import { probaLawFlip } from "../../../utils/alea/probaLawFlip.js";
13
+ import { random } from "../../../utils/alea/random.js";
14
+ import { handleVEAError } from "../../../utils/errors/handleVEAError.js";
15
+ import { joinanded } from "../../../utils/strings/joinanded.js";
16
+ const getHydrated = (identifiers) => {
17
+ const { graphIds, indexAsked } = identifiers;
18
+ const graph = GraphConstructor.fromIdentifiers(graphIds);
19
+ const nameVertexAsked = graph.vertexNames[indexAsked];
20
+ const arrNameVertexAdjacent = graph.getArrVertexNameAdjacent(nameVertexAsked);
21
+ return {
22
+ graph,
23
+ nameVertexAsked,
24
+ arrNameVertexAdjacent,
25
+ };
26
+ };
27
+ const getInstruction = (identifiers) => {
28
+ const { nameVertexAsked } = getHydrated(identifiers);
29
+ return `Un graphe est représenté ci-dessous.
30
+ Quel est le degré du sommet $${nameVertexAsked}$ ?`;
31
+ };
32
+ const getAnswerNode = (identifiers) => {
33
+ const { arrNameVertexAdjacent } = getHydrated(identifiers);
34
+ return arrNameVertexAdjacent.length.toTree();
35
+ };
36
+ const getAnswer = (identifiers) => {
37
+ return getAnswerNode(identifiers).toTex();
38
+ };
39
+ const getHint = () => {
40
+ return `Le degré d'un sommet est le nombre d'arêtes incidentes à ce sommet, sans tenir compte de leur sens de parcours.`;
41
+ };
42
+ const getCorrection = (identifiers) => {
43
+ const { nameVertexAsked, arrNameVertexAdjacent } = getHydrated(identifiers);
44
+ const nbAdjacent = arrNameVertexAdjacent.length;
45
+ return `Le sommet $${nameVertexAsked}$ a pour ${nbAdjacent === 1 ? "sommet adjacent" : "sommets adjacents"} ${joinanded(arrNameVertexAdjacent.map((nameVertex) => `$${nameVertex}$`), ", ", " et ")}.
46
+
47
+ Le degré de $${nameVertexAsked}$ est donc $${nbAdjacent.frenchify()}$.`;
48
+ };
49
+ const getCorrectionGGBOptions = (identifiers) => {
50
+ const { graphNodes, graphEdges } = identifiers;
51
+ const { graph, nameVertexAsked } = getHydrated(identifiers);
52
+ const arrPoint = graphNodes.map(({ label, x, y }) => new Point(label, x, y));
53
+ const pointCommands = arrPoint.flatMap((point) => point.toGGBCommand({
54
+ isFixed: false,
55
+ isSelectionnable: true,
56
+ showLabel: true,
57
+ style: 0,
58
+ size: 8,
59
+ color: point.name === nameVertexAsked ? greenMain : "#000000",
60
+ }));
61
+ const edgeCommands = graphEdges.flatMap((e, i) => {
62
+ return [
63
+ graph.isDirected
64
+ ? `edge${i + 1} = Vector(${e.from}, ${e.to})`
65
+ : `edge${i + 1} = Segment(${e.from}, ${e.to})`,
66
+ ...(e.from === nameVertexAsked || e.to === nameVertexAsked
67
+ ? [`SetColor(edge${i + 1}, "${greenMain}")`]
68
+ : []),
69
+ ];
70
+ });
71
+ const ggb = new GeogebraConstructor({
72
+ commands: [...pointCommands, ...edgeCommands],
73
+ fontSize: 16,
74
+ hideAxes: true,
75
+ hideGrid: true,
76
+ });
77
+ return ggb.getOptions({
78
+ coords: ggb.getCoordsForPoints(arrPoint),
79
+ });
80
+ };
81
+ const getGGBOptions = (identifiers) => {
82
+ const { graphNodes, graphEdges } = identifiers;
83
+ const { graph } = getHydrated(identifiers);
84
+ const arrPoint = graphNodes.map(({ label, x, y }) => new Point(label, x, y));
85
+ const pointCommands = arrPoint.flatMap((point) => point.toGGBCommand({
86
+ isFixed: false,
87
+ isSelectionnable: true,
88
+ showLabel: true,
89
+ style: 0,
90
+ size: 8,
91
+ }));
92
+ const edgeCommands = graphEdges.map((e, i) => graph.isDirected
93
+ ? `v${i + 1} = Vector(${e.from}, ${e.to})`
94
+ : `s${i + 1} = Segment(${e.from}, ${e.to})`);
95
+ const arrGGBCommandForGraph = [...pointCommands, ...edgeCommands];
96
+ const ggb = new GeogebraConstructor({
97
+ commands: [...arrGGBCommandForGraph],
98
+ fontSize: 16,
99
+ hideAxes: true,
100
+ hideGrid: true,
101
+ });
102
+ return ggb.getOptions({
103
+ coords: ggb.getCoordsForPoints(arrPoint),
104
+ });
105
+ };
106
+ const getPropositions = (n, { answer, ...identifiers }) => {
107
+ const propositions = [];
108
+ addValidProp(propositions, answer);
109
+ const { graph, nameVertexAsked } = getHydrated(identifiers);
110
+ //student: d -> d+ or d -> d-
111
+ if (graph.isDirected) {
112
+ const [_, dMinus, dPlus] = graph.getArrDegreeOfVertex(nameVertexAsked);
113
+ const [isAddWrongPropDMinus, isAddWrongPropDPlus] = probaLawFlip([
114
+ [[true, false], 0.4],
115
+ [[false, true], 0.4],
116
+ [[true, true], 0.2],
117
+ ]);
118
+ if (isAddWrongPropDMinus) {
119
+ tryToAddWrongProp(propositions, dMinus.frenchify());
120
+ }
121
+ if (isAddWrongPropDPlus) {
122
+ tryToAddWrongProp(propositions, dPlus.frenchify());
123
+ }
124
+ }
125
+ //student: degree of other vertex
126
+ {
127
+ [...Array(graph.vertexNames.length).keys()].forEach((index) => {
128
+ const identifiersWrong = {
129
+ ...identifiers,
130
+ indexAsked: index,
131
+ };
132
+ tryToAddWrongProp(propositions, getAnswer(identifiersWrong));
133
+ });
134
+ }
135
+ //filler
136
+ propWhile(propositions, n, () => {
137
+ const dWrong = randint(1, 10);
138
+ tryToAddWrongProp(propositions, dWrong.frenchify());
139
+ });
140
+ return shuffleProps(propositions, n);
141
+ };
142
+ const getKeys = () => {
143
+ return [];
144
+ };
145
+ const isAnswerValid = (ans, { answer }) => {
146
+ try {
147
+ const [nodeAns, nodeAnswer] = [ans, answer].map((str) => parseAlgebraic(str));
148
+ return NodeComparator.isEqualViaSub(nodeAns, nodeAnswer);
149
+ }
150
+ catch (err) {
151
+ return handleVEAError(err);
152
+ }
153
+ };
154
+ const createRandomIdentifiers = (isDirected) => {
155
+ const nbVertices = randint(5, 10);
156
+ const isSimple = true;
157
+ const minDensity = (() => {
158
+ switch (nbVertices) {
159
+ case 5:
160
+ return isDirected ? 0.4 : 0.62;
161
+ case 6:
162
+ return isDirected ? 0.35 : 0.57;
163
+ case 7:
164
+ return isDirected ? 0.3 : 0.52;
165
+ case 8:
166
+ return isDirected ? 0.27 : 0.37;
167
+ case 9:
168
+ return isDirected ? 0.24 : 0.32;
169
+ }
170
+ })();
171
+ const graph = GraphConstructor.random(nbVertices, isSimple, isDirected, minDensity, "ABCDEFGHIJKLM".split(""), true);
172
+ const indexAsked = randint(0, nbVertices);
173
+ const { nodes: graphNodes, edges: graphEdges } = GraphRenderer.renderToNodesAndEdges(graph);
174
+ const identifiers = {
175
+ graphIds: graph.toIdentifiers(),
176
+ indexAsked,
177
+ graphNodes,
178
+ graphEdges,
179
+ };
180
+ return identifiers;
181
+ };
182
+ const getGraphsDegreeOfVertexQuestion = (optsIn) => {
183
+ const arrayedOpts = defaultArrayedOptsWhereNeeded(optsIn, arrayedOptsDefault);
184
+ const opts = {
185
+ graphType: random(arrayedOpts.graphType),
186
+ };
187
+ const isDirected = opts.graphType === "orienté";
188
+ const identifiers = createRandomIdentifiers(isDirected);
189
+ return getQuestionFromIdentifiers(identifiers);
190
+ };
191
+ const getQuestionFromIdentifiers = (identifiers, opts) => {
192
+ const question = {
193
+ answer: getAnswer(identifiers, opts),
194
+ instruction: getInstruction(identifiers, opts),
195
+ keys: getKeys(identifiers, opts),
196
+ answerFormat: "tex",
197
+ identifiers,
198
+ hint: getHint(identifiers, opts),
199
+ correction: getCorrection(identifiers, opts),
200
+ correctionGgbOptions: getCorrectionGGBOptions(identifiers, opts),
201
+ ggbOptions: getGGBOptions(identifiers, opts),
202
+ };
203
+ return question;
204
+ };
205
+ const arrayedOptsDefault = {
206
+ graphType: ["non orienté"],
207
+ };
208
+ const options = [
209
+ {
210
+ id: "graphType",
211
+ label: "Types de graphes",
212
+ target: GeneratorOptionTarget.generation,
213
+ type: GeneratorOptionType.multiselect,
214
+ values: ["non orienté", "orienté"],
215
+ defaultValue: arrayedOptsDefault.graphType,
216
+ },
217
+ ];
218
+ export const graphsDegreeOfVertex = {
219
+ id: "graphsDegreeOfVertex",
220
+ label: "Déterminer le degré du sommet d'un graphe",
221
+ isSingleStep: true,
222
+ generator: (nb, opts) => getDistinctQuestions(() => getGraphsDegreeOfVertexQuestion(opts), nb),
223
+ options,
224
+ qcmTimer: 60,
225
+ freeTimer: 60,
226
+ isAnswerValid,
227
+ getPropositions,
228
+ subject: "Mathématiques",
229
+ getQuestionFromIdentifiers,
230
+ hasHintAndCorrection: true,
231
+ hasGeogebra: true,
232
+ };
@@ -0,0 +1,14 @@
1
+ import { Exercise } from "../../../exercises/exercise.js";
2
+ import { GraphIdentifiers } from "../../../math/graphs/graph.js";
3
+ import { GraphEdge, GraphNode } from "../../../math/utils/graphs/graphRenderer.js";
4
+ type Identifiers = {
5
+ graphIds: GraphIdentifiers;
6
+ graphNodes: GraphNode[];
7
+ graphEdges: GraphEdge[];
8
+ };
9
+ type Options = {
10
+ graphType: string;
11
+ };
12
+ export declare const graphsOrderOfGraph: Exercise<Identifiers, Options>;
13
+ export {};
14
+ //# sourceMappingURL=graphsOrderOfGraph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphsOrderOfGraph.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/graphs/graphsOrderOfGraph.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAoBT,MAAM,6BAA6B,CAAC;AAMrC,OAAO,EAAoB,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAChF,OAAO,EACL,SAAS,EACT,SAAS,EAEV,MAAM,0CAA0C,CAAC;AAUlD,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,gBAAgB,CAAC;IAG3B,UAAU,EAAE,SAAS,EAAE,CAAC;IACxB,UAAU,EAAE,SAAS,EAAE,CAAC;CACzB,CAAC;AAoPF,KAAK,OAAO,GAAG;IACb,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAsBF,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,WAAW,EAAE,OAAO,CAe7D,CAAC"}