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,11 @@
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
+ export declare const graphsCheckIsConnectedGraph: Exercise<Identifiers>;
10
+ export {};
11
+ //# sourceMappingURL=graphsCheckIsConnectedUndirectedGraph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphsCheckIsConnectedUndirectedGraph.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/graphs/graphsCheckIsConnectedUndirectedGraph.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAaT,MAAM,6BAA6B,CAAC;AAIrC,OAAO,EAGL,gBAAgB,EACjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,SAAS,EACT,SAAS,EAEV,MAAM,0CAA0C,CAAC;AASlD,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,gBAAgB,CAAC;IAG3B,UAAU,EAAE,SAAS,EAAE,CAAC;IACxB,UAAU,EAAE,SAAS,EAAE,CAAC;CACzB,CAAC;AA2OF,eAAO,MAAM,2BAA2B,EAAE,QAAQ,CAAC,WAAW,CAiB7D,CAAC"}
@@ -0,0 +1,178 @@
1
+ import { addValidProp, tryToAddWrongProp, } from "../../../exercises/exercise.js";
2
+ import { getDistinctQuestions } from "../../../exercises/utils/getDistinctQuestions.js";
3
+ import { GeogebraConstructor } from "../../../geogebra/geogebraConstructor.js";
4
+ import { Point } from "../../../math/geometry/point.js";
5
+ import { GraphConstructor, } from "../../../math/graphs/graph.js";
6
+ import { GraphRenderer, } from "../../../math/utils/graphs/graphRenderer.js";
7
+ import { randint } from "../../../math/utils/random/randint.js";
8
+ import { coinFlip } from "../../../utils/alea/coinFlip.js";
9
+ import { shuffle } from "../../../utils/alea/shuffle.js";
10
+ import { splitIntoRandomChunks } from "../../../utils/arrays/arrayChunks.js";
11
+ import { joinanded } from "../../../utils/strings/joinanded.js";
12
+ import * as Flatten from "@flatten-js/core";
13
+ const getHydrated = (identifiers) => {
14
+ const { graphIds } = identifiers;
15
+ const graph = GraphConstructor.fromIdentifiers(graphIds);
16
+ return {
17
+ graph,
18
+ };
19
+ };
20
+ const getInstruction = () => {
21
+ return `Un graphe non orienté est représenté ci-dessous.
22
+ Le graphe est-il connexe ?
23
+ *On peut déplacer les points sur la figure.*`;
24
+ };
25
+ const getAnswer = (identifiers) => {
26
+ const { graph } = getHydrated(identifiers);
27
+ return graph.isWeaklyConnected() ? "Oui" : "Non";
28
+ };
29
+ const getHint = () => {
30
+ return `Un graphe non orienté est connexe si et seulement si chaque couple de ses sommets peut être relié par une chaîne.`;
31
+ };
32
+ const getCorrection = (identifiers) => {
33
+ const { graph } = getHydrated(identifiers);
34
+ const arrWeaklyConnectedSubgraph = graph
35
+ .getWeaklyConnectedSubgraphChainsAsArrIndex()
36
+ .map((chain) => chain.map((index) => graph.vertexNames[index]));
37
+ if (graph.isWeaklyConnected()) {
38
+ const [chain0] = arrWeaklyConnectedSubgraph;
39
+ return `On peut former une chaîne qui relie tous les sommets : ${chain0
40
+ .map((str) => `$${str}$`)
41
+ .join("-")}.
42
+ Le graphe est donc connexe.`;
43
+ }
44
+ else {
45
+ return `On ne peut pas former une chaîne qui relie tous les sommets.
46
+ Le graphe contient des sous-graphes disjoints contenant les chaînes ${joinanded(arrWeaklyConnectedSubgraph.map((chain) => chain.map((str) => `$${str}$`).join("-")), ", ", " et ")}.
47
+ Le graphe n'est donc pas connexe.`;
48
+ }
49
+ };
50
+ const getGGBOptions = (identifiers) => {
51
+ const { graphNodes, graphEdges } = identifiers;
52
+ const { graph } = getHydrated(identifiers);
53
+ const arrPoint = graphNodes.map(({ label, x, y }) => new Point(label, x, y));
54
+ const pointCommands = arrPoint.flatMap((point) => point.toGGBCommand({
55
+ isFixed: false,
56
+ isSelectionnable: true,
57
+ showLabel: true,
58
+ style: 0,
59
+ size: 8,
60
+ }));
61
+ const edgeCommands = graphEdges.map((e, i) => graph.isDirected
62
+ ? `v${i + 1} = Vector(${e.from}, ${e.to})`
63
+ : `s${i + 1} = Segment(${e.from}, ${e.to})`);
64
+ const arrGGBCommandForGraph = [...pointCommands, ...edgeCommands];
65
+ const ggb = new GeogebraConstructor({
66
+ commands: [...arrGGBCommandForGraph],
67
+ fontSize: 16,
68
+ hideAxes: true,
69
+ hideGrid: true,
70
+ });
71
+ return ggb.getOptions({
72
+ coords: ggb.getCoordsForPoints(arrPoint),
73
+ });
74
+ };
75
+ const getPropositions = (_, { answer }) => {
76
+ const propositions = [];
77
+ ["Oui", "Non"].forEach((str) => {
78
+ if (str === answer) {
79
+ addValidProp(propositions, str, "raw");
80
+ }
81
+ else {
82
+ tryToAddWrongProp(propositions, str, "raw");
83
+ }
84
+ });
85
+ return propositions;
86
+ };
87
+ const createRandomIdentifiers = () => {
88
+ const nbVertices = randint(7, 9);
89
+ const isSimple = true;
90
+ const minDensity = 0.4;
91
+ const isConnected = coinFlip();
92
+ const vertexNames = "ABCDEFGHIJKLM".split("").slice(0, nbVertices);
93
+ const { graph, graphNodes, graphEdges } = (() => {
94
+ let isFound = false;
95
+ let graph;
96
+ let graphNodes;
97
+ let arrGraphEdges;
98
+ while (!isFound) {
99
+ const graphForPoints = GraphConstructor.randomConnected(nbVertices, isSimple, false, minDensity, vertexNames);
100
+ const { nodes: graphNodes0, edges: graphEdges0 } = GraphRenderer.renderToNodesAndEdges(graphForPoints, "circo");
101
+ graphNodes = graphNodes0;
102
+ let arrGraphNodes; //to check overlapping
103
+ [graph, arrGraphEdges, arrGraphNodes] = (() => {
104
+ if (isConnected) {
105
+ return [graphForPoints, [graphEdges0], [graphNodes0]];
106
+ }
107
+ else {
108
+ const arrVertexNamesChunk = splitIntoRandomChunks(shuffle(vertexNames), 3);
109
+ const arrSubGraph = arrVertexNamesChunk.map((vertexNamesChunk) => GraphConstructor.randomConnected(vertexNamesChunk.length, isSimple, false, minDensity, vertexNamesChunk));
110
+ const graph = GraphConstructor.graphByMergingSimpleGraphs(arrSubGraph);
111
+ const arrGraphEdges = arrSubGraph.map((graph) => graph.arrConnection().map(([from, to, _]) => {
112
+ return { from, to };
113
+ }));
114
+ const dictGraphNodes = Object.fromEntries(graphNodes.map((graphNode) => [graphNode.label, graphNode]));
115
+ const arrGraphNodes = arrSubGraph.map((graph) => graph.vertexNames.map((nameVertex) => dictGraphNodes[nameVertex]));
116
+ return [graph, arrGraphEdges, arrGraphNodes];
117
+ }
118
+ })();
119
+ const arrGraphNodes1GraphNodes2 = [...Array(arrGraphNodes.length).keys()]
120
+ .flatMap((i) => [...Array(i + 1).keys()].map((j) => [i, j]))
121
+ .map(([i, j]) => [arrGraphNodes[i], arrGraphNodes[j]]);
122
+ try {
123
+ isFound = arrGraphNodes1GraphNodes2.every(([graphNodes1, graphNodes2]) => {
124
+ const [polygon1, polygon2] = [graphNodes1, graphNodes2].map((graphNodes) => {
125
+ const arrPoint = graphNodes.map(({ x, y }) => new Flatten.Point(x, y));
126
+ const polygon = new Flatten.Polygon(arrPoint);
127
+ return polygon;
128
+ });
129
+ return Flatten.Relations.intersect(polygon1, polygon2);
130
+ });
131
+ }
132
+ catch {
133
+ isFound = false;
134
+ }
135
+ }
136
+ const graphEdges = arrGraphEdges.reduce((acc, graphEdges) => {
137
+ acc = [...acc, ...graphEdges];
138
+ return acc;
139
+ }, []);
140
+ return { graph: graph, graphNodes: graphNodes, graphEdges };
141
+ })();
142
+ const identifiers = {
143
+ graphIds: graph.toIdentifiers(),
144
+ graphNodes,
145
+ graphEdges,
146
+ };
147
+ return identifiers;
148
+ };
149
+ const getGraphsCheckIsConnectedGraphQuestion = () => {
150
+ const identifiers = createRandomIdentifiers();
151
+ return getQuestionFromIdentifiers(identifiers);
152
+ };
153
+ const getQuestionFromIdentifiers = (identifiers, opts) => {
154
+ const question = {
155
+ answer: getAnswer(identifiers, opts),
156
+ instruction: getInstruction(identifiers, opts),
157
+ answerFormat: "raw",
158
+ identifiers,
159
+ hint: getHint(identifiers, opts),
160
+ correction: getCorrection(identifiers, opts),
161
+ ggbOptions: getGGBOptions(identifiers, opts),
162
+ };
163
+ return question;
164
+ };
165
+ export const graphsCheckIsConnectedGraph = {
166
+ id: "graphsCheckIsConnectedGraph",
167
+ label: "Déterminer si un graphe est connexe",
168
+ isSingleStep: true,
169
+ generator: (nb, opts) => getDistinctQuestions(() => getGraphsCheckIsConnectedGraphQuestion(opts), nb),
170
+ qcmTimer: 60,
171
+ freeTimer: 60,
172
+ getPropositions,
173
+ subject: "Mathématiques",
174
+ getQuestionFromIdentifiers,
175
+ hasHintAndCorrection: true,
176
+ hasGeogebra: true,
177
+ answerType: "QCU",
178
+ };
@@ -0,0 +1,19 @@
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
+ graphIds1: GraphIdentifiers;
6
+ graphIds2: GraphIdentifiers;
7
+ graphNodes1: GraphNode[];
8
+ graphEdges1: GraphEdge[];
9
+ scale1: number;
10
+ graphNodes2: GraphNode[];
11
+ graphEdges2: GraphEdge[];
12
+ scale2: number;
13
+ };
14
+ type Options = {
15
+ graphType: string;
16
+ };
17
+ export declare const graphsCheckIsSameGraph: Exercise<Identifiers, Options>;
18
+ export {};
19
+ //# sourceMappingURL=graphsCheckIsSameGraph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphsCheckIsSameGraph.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/graphs/graphsCheckIsSameGraph.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAgBT,MAAM,6BAA6B,CAAC;AAMrC,OAAO,EAEL,gBAAgB,EAEjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,SAAS,EACT,SAAS,EAEV,MAAM,0CAA0C,CAAC;AAQlD,KAAK,WAAW,GAAG;IACjB,SAAS,EAAE,gBAAgB,CAAC;IAC5B,SAAS,EAAE,gBAAgB,CAAC;IAG5B,WAAW,EAAE,SAAS,EAAE,CAAC;IACzB,WAAW,EAAE,SAAS,EAAE,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;IAEf,WAAW,EAAE,SAAS,EAAE,CAAC;IACzB,WAAW,EAAE,SAAS,EAAE,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAyXF,KAAK,OAAO,GAAG;IACb,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAsBF,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAAC,WAAW,EAAE,OAAO,CAejE,CAAC"}
@@ -0,0 +1,301 @@
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 { GeogebraConstructor } from "../../../geogebra/geogebraConstructor.js";
5
+ import { Point } from "../../../math/geometry/point.js";
6
+ import { Vector } from "../../../math/geometry/vector.js";
7
+ import { GraphConstructor, Graph, } 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 { probaLawFlip } from "../../../utils/alea/probaLawFlip.js";
12
+ import { random, randomMany } from "../../../utils/alea/random.js";
13
+ import { shuffle } from "../../../utils/alea/shuffle.js";
14
+ const getHydrated = (identifiers) => {
15
+ const { graphIds1, graphIds2, graphNodes1, graphEdges1, graphNodes2, graphEdges2, } = identifiers;
16
+ const [graph1, graph2] = [graphIds1, graphIds2].map((graphIds) => GraphConstructor.fromIdentifiers(graphIds));
17
+ const isSameGraph = graph1.equals(graph2);
18
+ const graphNodeOnlyIn2 = (() => {
19
+ if (isSameGraph) {
20
+ return undefined;
21
+ }
22
+ else {
23
+ return graphNodes2.find(({ label: label2 }) => !graphNodes1.map(({ label }) => label).includes(label2));
24
+ }
25
+ })();
26
+ const graphEdgeOnlyIn2 = (() => {
27
+ if (isSameGraph) {
28
+ return undefined;
29
+ }
30
+ else {
31
+ return graphEdges2.find(({ from: from2, to: to2 }) => !graphEdges1
32
+ .map(({ from, to }) => `${from}-${to}`)
33
+ .includes(`${from2}-${to2}`));
34
+ }
35
+ })();
36
+ return {
37
+ graph1,
38
+ graph2,
39
+ isSameGraph,
40
+ graphNodeOnlyIn2,
41
+ graphEdgeOnlyIn2,
42
+ };
43
+ };
44
+ const getInstruction = () => {
45
+ return `Deux graphes sont représentés ci-dessous.
46
+ S'agit-il du même graphe ?
47
+
48
+ *On peut déplacer les points sur la figure.*`;
49
+ };
50
+ const getAnswer = (identifiers) => {
51
+ const { isSameGraph } = getHydrated(identifiers);
52
+ return isSameGraph ? "Oui" : "Non";
53
+ };
54
+ const getHint = () => {
55
+ return `Si les sommets et les arêtes correspondent deux à deux alors il s'agit du même graphe, représenté de deux façons différentes.`;
56
+ };
57
+ const getCorrection = (identifiers) => {
58
+ const { graph2, isSameGraph, graphNodeOnlyIn2, graphEdgeOnlyIn2 } = getHydrated(identifiers);
59
+ if (isSameGraph) {
60
+ return `Les sommets et les arêtes correspondent deux à deux donc il s'agit du même graphe, représenté de deux façons différentes.`;
61
+ }
62
+ else {
63
+ if (graphNodeOnlyIn2) {
64
+ return `Le sommet $${graphNodeOnlyIn2.label}$ est présent dans le graphe de droite et pas dans celui de gauche.
65
+ Ce sont donc des graphes différents.`;
66
+ }
67
+ else if (graphEdgeOnlyIn2) {
68
+ return `L'arête $${graph2.isDirected
69
+ ? `${graphEdgeOnlyIn2.from} \\rightarrow ${graphEdgeOnlyIn2.to}`
70
+ : `${graphEdgeOnlyIn2.from}-${graphEdgeOnlyIn2.to}`}$ est présente dans le graphe de droite et pas dans celui de gauche.
71
+ Ce sont donc des graphes différents.`;
72
+ }
73
+ else {
74
+ throw new Error("!isSameGraph && !graphNodeOnlyIn2 && !graphEdgeOnlyIn2");
75
+ }
76
+ }
77
+ };
78
+ // const getCorrectionGGBOptions: GetGGBOptions<Identifiers> = (identifiers) => {
79
+ // const ggb = new GeogebraConstructor({
80
+ // commands: ["p = (0,1)"],
81
+ // fontSize: 16,
82
+ // hideAxes: true,
83
+ // hideGrid: true,
84
+ // });
85
+ // return ggb.getOptions({
86
+ // coords: ggb.getCoordsForPoints([
87
+ // new Point("O", 0, 0),
88
+ // new Point("A", 1, 0),
89
+ // ]),
90
+ // });
91
+ // };
92
+ const getGGBOptions = (identifiers) => {
93
+ const { graphNodes1, graphEdges1, scale1, graphNodes2, graphEdges2, scale2 } = identifiers;
94
+ const { graph1, graph2 } = getHydrated(identifiers);
95
+ function createDisplayObjForGraph(graph, graphNodes, graphEdges, scale, index, vecOffset = new Vector("offset", (0).toTree(), (0).toTree())) {
96
+ const arrDictPoint = graphNodes
97
+ .map(({ label, x, y }) => new Point(label, x * scale, y * scale))
98
+ .map((point) => {
99
+ const strNamePointOld = point.name;
100
+ const strNamePointNew = `${point.name}${index}`;
101
+ return {
102
+ label: strNamePointOld,
103
+ point: vecOffset.getEndPoint(point, strNamePointNew),
104
+ };
105
+ });
106
+ const pointCommands = arrDictPoint.flatMap(({ label, point }) => point.toGGBCommand({
107
+ isFixed: false,
108
+ isSelectionnable: true,
109
+ showLabel: true,
110
+ style: 0,
111
+ size: 8,
112
+ label,
113
+ }));
114
+ const edgeCommands = graphEdges.map((e, i) => graph.isDirected
115
+ ? `v${index}I${i + 1} = Vector(${e.from}${index}, ${e.to}${index})`
116
+ : `s${index}I${i + 1} = Segment(${e.from}${index}, ${e.to}${index})`);
117
+ const arrGGBCommandForGraph = [...pointCommands, ...edgeCommands];
118
+ const arrPoint = arrDictPoint.map(({ point }) => point);
119
+ return {
120
+ arrPoint,
121
+ arrGGBCommandForGraph,
122
+ };
123
+ }
124
+ const { arrPoint: arrPoint1, arrGGBCommandForGraph: arrGGBCommandForGraph1 } = createDisplayObjForGraph(graph1, graphNodes1, graphEdges1, scale1, 1);
125
+ const xMin1 = Math.min(...arrPoint1.map((point) => point.x.evaluate()));
126
+ const xMax1 = Math.max(...arrPoint1.map((point) => point.x.evaluate()));
127
+ const width1 = xMax1 - xMin1;
128
+ const vecOffset = new Vector("offset", (xMax1 + 0.1 * width1).toTree(), (0).toTree());
129
+ const { arrPoint: arrPoint2, arrGGBCommandForGraph: arrGGBCommandForGraph2 } = createDisplayObjForGraph(graph2, graphNodes2, graphEdges2, scale2, 2, vecOffset);
130
+ const ggb = new GeogebraConstructor({
131
+ commands: [...arrGGBCommandForGraph1, ...arrGGBCommandForGraph2],
132
+ fontSize: 16,
133
+ hideAxes: true,
134
+ hideGrid: true,
135
+ });
136
+ return ggb.getOptions({
137
+ coords: ggb.getCoordsForPoints([...arrPoint1, ...arrPoint2]),
138
+ });
139
+ };
140
+ const getPropositions = (_, { answer }) => {
141
+ const propositions = [];
142
+ ["Oui", "Non"].forEach((str) => {
143
+ if (str === answer) {
144
+ addValidProp(propositions, str, "raw");
145
+ }
146
+ else {
147
+ tryToAddWrongProp(propositions, str, "raw");
148
+ }
149
+ });
150
+ return propositions;
151
+ };
152
+ const createRandomIdentifiers = (isDirected) => {
153
+ const isSimple = true;
154
+ const graph0 = (() => {
155
+ const nbVertices = randint(6, 8);
156
+ const minDensity = (() => {
157
+ switch (nbVertices) {
158
+ case 5:
159
+ return isDirected ? 0.4 : 0.62;
160
+ case 6:
161
+ return isDirected ? 0.35 : 0.57;
162
+ case 7:
163
+ return isDirected ? 0.3 : 0.52;
164
+ case 8:
165
+ return isDirected ? 0.27 : 0.37;
166
+ case 9:
167
+ return isDirected ? 0.24 : 0.32;
168
+ }
169
+ })();
170
+ const graph = GraphConstructor.random(nbVertices, isSimple, isDirected, minDensity, "ABCDEFGHIJKLM".split(""), true);
171
+ return graph;
172
+ })();
173
+ const isSameGraph = coinFlip();
174
+ const [graph1, graph2] = (() => {
175
+ if (isSameGraph) {
176
+ return [graph0, graph0];
177
+ }
178
+ else {
179
+ const poolVertexName = "ABCDEFGHIJKLM".split("");
180
+ const poolVertexNameAvailable = poolVertexName.filter((str) => !graph0.vertexNames.includes(str));
181
+ const typeDiff = probaLawFlip([
182
+ ["different vertex names", 0.25],
183
+ ["extraneous vertex", 0.25],
184
+ ["same vertices, extraneous edge", 0.5],
185
+ ]);
186
+ switch (typeDiff) {
187
+ case "different vertex names": {
188
+ const [nameVertex1, nameVertex2] = randomMany(poolVertexNameAvailable, 2);
189
+ const indexReplacement = randint(0, graph0.vertexNames.length);
190
+ const [vertexNames1, vertexNames2] = [nameVertex1, nameVertex2].map((nameVertex) => {
191
+ const vertexNames = [...graph0.vertexNames];
192
+ vertexNames[indexReplacement] = nameVertex;
193
+ return vertexNames;
194
+ });
195
+ const [graph1, graph2] = [vertexNames1, vertexNames2].map((vertexNames) => new Graph(vertexNames, graph0.mat));
196
+ return [graph1, graph2];
197
+ }
198
+ case "extraneous vertex": {
199
+ const isGraph1Graph0 = coinFlip();
200
+ const graph1 = isGraph1Graph0
201
+ ? graph0
202
+ : (() => {
203
+ const miniGraph = GraphConstructor.random(2, isSimple, graph0.isDirected, 0, [random(graph0.vertexNames), random(poolVertexNameAvailable)], true);
204
+ return GraphConstructor.graphByMergingSimpleGraphs([
205
+ graph0,
206
+ miniGraph,
207
+ ]);
208
+ })();
209
+ const graph2 = (() => {
210
+ const poolVertexNameAvailable = poolVertexName.filter((str) => !graph1.vertexNames.includes(str));
211
+ const miniGraph = GraphConstructor.random(2, isSimple, graph0.isDirected, 0, [random(graph0.vertexNames), random(poolVertexNameAvailable)], true);
212
+ return GraphConstructor.graphByMergingSimpleGraphs([
213
+ graph0,
214
+ miniGraph,
215
+ ]);
216
+ })();
217
+ return [graph1, graph2];
218
+ }
219
+ case "same vertices, extraneous edge": {
220
+ //it is possible that graph1===graph2
221
+ const isGraph1Graph0 = coinFlip();
222
+ const graph1 = isGraph1Graph0
223
+ ? graph0
224
+ : GraphConstructor.graphByAddingRandomEdge(graph0);
225
+ const graph2 = GraphConstructor.graphByAddingRandomEdge(graph0);
226
+ return [graph1, graph2];
227
+ }
228
+ default:
229
+ throw new Error("Unsupported typeDiff: " + typeDiff);
230
+ }
231
+ }
232
+ })();
233
+ const [[layoutEngine1, scale1], [layoutEngine2, scale2]] = shuffle([
234
+ ["fdp", 1.5],
235
+ ["circo", 1.0],
236
+ ]);
237
+ const [{ nodes: graphNodes1, edges: graphEdges1 }, { nodes: graphNodes2, edges: graphEdges2 },] = [
238
+ { graph: graph1, layoutEngine: layoutEngine1 },
239
+ { graph: graph2, layoutEngine: layoutEngine2 },
240
+ ].map(({ graph, layoutEngine }) => GraphRenderer.renderToNodesAndEdges(graph, layoutEngine));
241
+ const identifiers = {
242
+ graphIds1: graph1.toIdentifiers(),
243
+ graphIds2: graph2.toIdentifiers(),
244
+ graphNodes1,
245
+ graphEdges1,
246
+ scale1,
247
+ graphNodes2,
248
+ graphEdges2,
249
+ scale2,
250
+ };
251
+ return identifiers;
252
+ };
253
+ const getGraphsCheckIsSameGraphQuestion = (optsIn) => {
254
+ const arrayedOpts = defaultArrayedOptsWhereNeeded(optsIn, arrayedOptsDefault);
255
+ const opts = {
256
+ graphType: random(arrayedOpts.graphType),
257
+ };
258
+ const isDirected = opts.graphType === "orienté";
259
+ const identifiers = createRandomIdentifiers(isDirected);
260
+ return getQuestionFromIdentifiers(identifiers);
261
+ };
262
+ const getQuestionFromIdentifiers = (identifiers, opts) => {
263
+ const question = {
264
+ answer: getAnswer(identifiers, opts),
265
+ instruction: getInstruction(identifiers, opts),
266
+ answerFormat: "raw",
267
+ identifiers,
268
+ hint: getHint(identifiers, opts),
269
+ correction: getCorrection(identifiers, opts),
270
+ ggbOptions: getGGBOptions(identifiers, opts),
271
+ };
272
+ return question;
273
+ };
274
+ const arrayedOptsDefault = {
275
+ graphType: ["non orienté"],
276
+ };
277
+ const options = [
278
+ {
279
+ id: "graphType",
280
+ label: "Types de graphes",
281
+ target: GeneratorOptionTarget.generation,
282
+ type: GeneratorOptionType.multiselect,
283
+ values: ["non orienté", "orienté"],
284
+ defaultValue: arrayedOptsDefault.graphType,
285
+ },
286
+ ];
287
+ export const graphsCheckIsSameGraph = {
288
+ id: "graphsCheckIsSameGraph",
289
+ label: "Déterminer s'il s'agit du même graphe",
290
+ isSingleStep: true,
291
+ generator: (nb, opts) => getDistinctQuestions(() => getGraphsCheckIsSameGraphQuestion(opts), nb),
292
+ options,
293
+ qcmTimer: 60,
294
+ freeTimer: 60,
295
+ getPropositions,
296
+ subject: "Mathématiques",
297
+ getQuestionFromIdentifiers,
298
+ hasHintAndCorrection: true,
299
+ hasGeogebra: true,
300
+ answerType: "QCU",
301
+ };
@@ -0,0 +1,16 @@
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
+ nameVertex1: string;
7
+ nameVertex2: string;
8
+ graphNodes: GraphNode[];
9
+ graphEdges: GraphEdge[];
10
+ };
11
+ type Options = {
12
+ graphType: string;
13
+ };
14
+ export declare const graphsCheckIsVerticesAdjacent: Exercise<Identifiers, Options>;
15
+ export {};
16
+ //# sourceMappingURL=graphsCheckIsVerticesAdjacent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphsCheckIsVerticesAdjacent.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/graphs/graphsCheckIsVerticesAdjacent.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAgBT,MAAM,6BAA6B,CAAC;AAMrC,OAAO,EAAoB,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAChF,OAAO,EACL,SAAS,EACT,SAAS,EAEV,MAAM,0CAA0C,CAAC;AAMlD,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IAGpB,UAAU,EAAE,SAAS,EAAE,CAAC;IACxB,UAAU,EAAE,SAAS,EAAE,CAAC;CACzB,CAAC;AAkOF,KAAK,OAAO,GAAG;IACb,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAsBF,eAAO,MAAM,6BAA6B,EAAE,QAAQ,CAAC,WAAW,EAAE,OAAO,CAkBxE,CAAC"}