math-exercises 1.1.0 → 1.2.0

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 (124) hide show
  1. package/package.json +2 -2
  2. package/src/exercises/calcul/addAndSub.js +19 -13
  3. package/src/exercises/calcul/addAndSub.ts +31 -23
  4. package/src/exercises/calcul/fractions/fractionAndIntegerDivision.js +35 -0
  5. package/src/exercises/calcul/fractions/fractionAndIntegerDivision.ts +38 -0
  6. package/src/exercises/calcul/fractions/fractionAndIntegerProduct.js +31 -0
  7. package/src/exercises/calcul/fractions/fractionAndIntegerProduct.ts +32 -0
  8. package/src/exercises/calcul/fractions/fractionAndIntegerSum.js +32 -0
  9. package/src/exercises/calcul/fractions/fractionAndIntegerSum.ts +31 -0
  10. package/src/exercises/calcul/fractions/fractionsDivision.js +29 -0
  11. package/src/exercises/calcul/fractions/fractionsDivision.ts +30 -0
  12. package/src/exercises/calcul/fractions/fractionsProduct.js +29 -0
  13. package/src/exercises/calcul/fractions/fractionsProduct.ts +29 -0
  14. package/src/exercises/calcul/fractions/fractionsSum.js +29 -0
  15. package/src/exercises/calcul/fractions/fractionsSum.ts +28 -0
  16. package/src/exercises/calcul/fractions/simplifyFraction.js +25 -0
  17. package/src/exercises/calcul/fractions/simplifyFraction.ts +24 -0
  18. package/src/exercises/calcul/operationsPriorities.js +89 -0
  19. package/src/exercises/calcul/operationsPriorities.ts +118 -0
  20. package/src/exercises/calcul/rounding/roundToUnit.js +70 -0
  21. package/src/exercises/calcul/rounding/roundToUnit.ts +68 -0
  22. package/src/exercises/calculLitteral/distributivity/allIdentities.js +2 -0
  23. package/src/exercises/calculLitteral/distributivity/allIdentities.ts +2 -0
  24. package/src/exercises/calculLitteral/distributivity/doubleDistributivity.js +3 -3
  25. package/src/exercises/calculLitteral/distributivity/doubleDistributivity.ts +2 -0
  26. package/src/exercises/calculLitteral/distributivity/firstIdentity.js +2 -0
  27. package/src/exercises/calculLitteral/distributivity/firstIdentity.ts +2 -0
  28. package/src/exercises/calculLitteral/distributivity/secondIdentity.js +3 -3
  29. package/src/exercises/calculLitteral/distributivity/secondIdentity.ts +2 -0
  30. package/src/exercises/calculLitteral/distributivity/simpleDistributivity.js +3 -3
  31. package/src/exercises/calculLitteral/distributivity/simpleDistributivity.ts +2 -0
  32. package/src/exercises/calculLitteral/distributivity/thirdIdentity.js +4 -2
  33. package/src/exercises/calculLitteral/distributivity/thirdIdentity.ts +2 -0
  34. package/src/exercises/calculLitteral/equation/equationType1Exercise.js +3 -3
  35. package/src/exercises/calculLitteral/equation/equationType1Exercise.ts +4 -5
  36. package/src/exercises/calculLitteral/equation/equationType2Exercise.js +3 -3
  37. package/src/exercises/calculLitteral/equation/equationType2Exercise.ts +5 -5
  38. package/src/exercises/calculLitteral/equation/equationType3Exercise.js +3 -3
  39. package/src/exercises/calculLitteral/equation/equationType3Exercise.ts +5 -5
  40. package/src/exercises/calculLitteral/equation/equationType4Exercise.js +3 -3
  41. package/src/exercises/calculLitteral/equation/equationType4Exercise.ts +7 -12
  42. package/src/exercises/calculLitteral/factorisation/factoType1Exercise.js +4 -9
  43. package/src/exercises/calculLitteral/factorisation/factoType1Exercise.ts +3 -6
  44. package/src/exercises/calculLitteral/reduction.ts +27 -0
  45. package/src/exercises/exercise.ts +2 -0
  46. package/src/exercises/exercises.js +83 -0
  47. package/src/exercises/exercises.ts +58 -0
  48. package/src/exercises/powers/powersDivision.js +46 -0
  49. package/src/exercises/powers/powersDivision.ts +51 -0
  50. package/src/exercises/powers/powersOfTenToDecimal.js +33 -0
  51. package/src/exercises/powers/powersOfTenToDecimal.ts +37 -0
  52. package/src/exercises/powers/powersPower.js +45 -0
  53. package/src/exercises/powers/powersPower.ts +55 -0
  54. package/src/exercises/powers/powersProduct.js +46 -0
  55. package/src/exercises/powers/powersProduct.ts +51 -0
  56. package/src/exercises/powers/scientificToDecimal.js +38 -0
  57. package/src/exercises/powers/scientificToDecimal.ts +44 -0
  58. package/src/exercises/squareRoots/simpifySquareRoot.js +2 -3
  59. package/src/exercises/squareRoots/simpifySquareRoot.ts +2 -0
  60. package/src/index.js +8 -8
  61. package/src/index.ts +5 -16
  62. package/src/mathutils/arithmetic/coprimesOf.js +13 -0
  63. package/src/mathutils/arithmetic/coprimesOf.ts +9 -0
  64. package/src/mathutils/arithmetic/dividersOf.ts +7 -0
  65. package/src/mathutils/arithmetic/lcd.js +12 -0
  66. package/src/mathutils/arithmetic/lcd.ts +7 -0
  67. package/src/mathutils/arithmetic/nonCoprimesOf.ts +9 -0
  68. package/src/mathutils/arithmetic/nonDividersOf.ts +12 -0
  69. package/src/mathutils/decimals/decimalPartLengthOf.ts +10 -0
  70. package/src/mathutils/random/randint.js +11 -2
  71. package/src/mathutils/random/randint.ts +10 -2
  72. package/src/numbers/decimals/decimal.js +144 -0
  73. package/src/numbers/decimals/decimal.ts +140 -0
  74. package/src/numbers/integer/integer.js +61 -4
  75. package/src/numbers/integer/integer.ts +58 -7
  76. package/src/numbers/integer/power.js +53 -0
  77. package/src/numbers/integer/power.ts +49 -0
  78. package/src/numbers/nombre.js +3 -2
  79. package/src/numbers/nombre.ts +2 -0
  80. package/src/numbers/rationals/rational.js +96 -10
  81. package/src/numbers/rationals/rational.ts +81 -15
  82. package/src/numbers/reals/real.js +2 -0
  83. package/src/numbers/reals/real.ts +3 -1
  84. package/src/numbers/reals/squareRoot.ts +3 -10
  85. package/src/polynomials/affine.ts +2 -6
  86. package/src/polynomials/polynomial.js +4 -13
  87. package/src/polynomials/polynomial.ts +8 -25
  88. package/src/tree/latexParser/latexParse.js +81 -34
  89. package/src/tree/latexParser/latexParse.ts +85 -39
  90. package/src/tree/nodes/functions/functionNode.js +19 -0
  91. package/src/tree/nodes/functions/functionNode.ts +18 -0
  92. package/src/tree/nodes/functions/oppositeNode.js +30 -0
  93. package/src/tree/nodes/functions/oppositeNode.ts +12 -0
  94. package/src/tree/nodes/functions/sqrtNode.js +24 -9
  95. package/src/tree/nodes/functions/sqrtNode.ts +5 -9
  96. package/src/tree/nodes/node.ts +1 -3
  97. package/src/tree/nodes/numbers/numberNode.js +3 -6
  98. package/src/tree/nodes/numbers/numberNode.ts +4 -7
  99. package/src/tree/nodes/operators/addNode.js +23 -8
  100. package/src/tree/nodes/operators/addNode.ts +3 -7
  101. package/src/tree/nodes/operators/divideNode.js +21 -9
  102. package/src/tree/nodes/operators/divideNode.ts +4 -11
  103. package/src/tree/nodes/operators/equalNode.js +20 -8
  104. package/src/tree/nodes/operators/equalNode.ts +3 -9
  105. package/src/tree/nodes/operators/fractionNode.js +34 -0
  106. package/src/tree/nodes/operators/fractionNode.ts +16 -0
  107. package/src/tree/nodes/operators/multiplyNode.js +20 -8
  108. package/src/tree/nodes/operators/multiplyNode.ts +3 -9
  109. package/src/tree/nodes/operators/operatorNode.js +35 -0
  110. package/src/tree/nodes/operators/operatorNode.ts +35 -2
  111. package/src/tree/nodes/operators/powerNode.js +20 -8
  112. package/src/tree/nodes/operators/powerNode.ts +3 -8
  113. package/src/tree/nodes/operators/substractNode.js +20 -8
  114. package/src/tree/nodes/operators/substractNode.ts +3 -9
  115. package/src/tree/nodes/variables/variableNode.js +1 -4
  116. package/src/tree/nodes/variables/variableNode.ts +4 -7
  117. package/src/utils/coin.js +7 -0
  118. package/src/utils/coin.ts +3 -0
  119. package/src/utils/shuffle.js +15 -4
  120. package/src/utils/shuffle.ts +7 -5
  121. package/src/exercises/calcul/priority.ts +0 -33
  122. package/src/expression/expression.js +0 -9
  123. package/src/expression/expression.ts +0 -13
  124. package/src/tree/nodes/operators/oppositeNode.ts +0 -17
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.getPowersProductQuestion = exports.powersProduct = exports.powersOfTenProduct = void 0;
4
+ var randint_1 = require("../../mathutils/random/randint");
5
+ var power_1 = require("../../numbers/integer/power");
6
+ var latexParse_1 = require("../../tree/latexParser/latexParse");
7
+ var numberNode_1 = require("../../tree/nodes/numbers/numberNode");
8
+ var multiplyNode_1 = require("../../tree/nodes/operators/multiplyNode");
9
+ var powerNode_1 = require("../../tree/nodes/operators/powerNode");
10
+ var getDistinctQuestions_1 = require("../utils/getDistinctQuestions");
11
+ /**
12
+ * a^b*a^c
13
+ */
14
+ exports.powersOfTenProduct = {
15
+ id: "powersOfTenProduct",
16
+ connector: "=",
17
+ instruction: "Calculer :",
18
+ label: "Multiplication de puissances de 10",
19
+ levels: ["4", "3", "2", "1"],
20
+ section: "Calculs",
21
+ isSingleStep: true,
22
+ generator: function (nb) { return (0, getDistinctQuestions_1.getDistinctQuestions)(function () { return getPowersProductQuestion(true); }, nb); }
23
+ };
24
+ exports.powersProduct = {
25
+ id: "powersProduct",
26
+ connector: "=",
27
+ instruction: "Calculer :",
28
+ label: "Multiplication de puissances",
29
+ levels: ["4", "3", "2", "1"],
30
+ section: "Puissances",
31
+ isSingleStep: true,
32
+ generator: function (nb) { return (0, getDistinctQuestions_1.getDistinctQuestions)(getPowersProductQuestion, nb); }
33
+ };
34
+ function getPowersProductQuestion(useOnlyPowersOfTen) {
35
+ if (useOnlyPowersOfTen === void 0) { useOnlyPowersOfTen = false; }
36
+ var a = useOnlyPowersOfTen ? 10 : (0, randint_1.randint)(-11, 11);
37
+ var _a = [1, 2].map(function (el) { return (0, randint_1.randint)(-11, 11); }), b = _a[0], c = _a[1];
38
+ var statement = new multiplyNode_1.MultiplyNode(new powerNode_1.PowerNode(new numberNode_1.NumberNode(a), new numberNode_1.NumberNode(b)), new powerNode_1.PowerNode(new numberNode_1.NumberNode(a), new numberNode_1.NumberNode(c)));
39
+ var answerTree = new power_1.Power(a, b + c).simplify();
40
+ var question = {
41
+ statement: (0, latexParse_1.latexParse)(statement),
42
+ answer: (0, latexParse_1.latexParse)(answerTree)
43
+ };
44
+ return question;
45
+ }
46
+ exports.getPowersProductQuestion = getPowersProductQuestion;
@@ -0,0 +1,51 @@
1
+ import { randint } from "../../mathutils/random/randint";
2
+ import { Power } from "../../numbers/integer/power";
3
+ import { latexParse } from "../../tree/latexParser/latexParse";
4
+ import { NumberNode } from "../../tree/nodes/numbers/numberNode";
5
+ import { MultiplyNode } from "../../tree/nodes/operators/multiplyNode";
6
+ import { PowerNode } from "../../tree/nodes/operators/powerNode";
7
+ import { Exercise, Question } from "../exercise";
8
+ import { getDistinctQuestions } from "../utils/getDistinctQuestions";
9
+
10
+ /**
11
+ * a^b*a^c
12
+ */
13
+
14
+ export const powersOfTenProduct: Exercise = {
15
+ id: "powersOfTenProduct",
16
+ connector: "=",
17
+ instruction: "Calculer :",
18
+ label: "Multiplication de puissances de 10",
19
+ levels: ["4", "3", "2", "1"],
20
+ section: "Calculs",
21
+ isSingleStep: true,
22
+ generator: (nb: number) => getDistinctQuestions(() => getPowersProductQuestion(true), nb),
23
+ };
24
+
25
+ export const powersProduct: Exercise = {
26
+ id: "powersProduct",
27
+ connector: "=",
28
+ instruction: "Calculer :",
29
+ label: "Multiplication de puissances",
30
+ levels: ["4", "3", "2", "1"],
31
+ section: "Puissances",
32
+ isSingleStep: true,
33
+ generator: (nb: number) => getDistinctQuestions(getPowersProductQuestion, nb),
34
+ };
35
+
36
+ export function getPowersProductQuestion(useOnlyPowersOfTen: boolean = false): Question {
37
+ const a = useOnlyPowersOfTen ? 10 : randint(-11, 11);
38
+ const [b, c] = [1, 2].map((el) => randint(-11, 11));
39
+
40
+ const statement = new MultiplyNode(
41
+ new PowerNode(new NumberNode(a), new NumberNode(b)),
42
+ new PowerNode(new NumberNode(a), new NumberNode(c))
43
+ );
44
+ const answerTree = new Power(a, b + c).simplify();
45
+
46
+ const question: Question = {
47
+ statement: latexParse(statement),
48
+ answer: latexParse(answerTree),
49
+ };
50
+ return question;
51
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.getScientificToDecimalQuestion = exports.scientificToDecimal = void 0;
4
+ var randint_1 = require("../../mathutils/random/randint");
5
+ var decimal_1 = require("../../numbers/decimals/decimal");
6
+ var integer_1 = require("../../numbers/integer/integer");
7
+ var latexParse_1 = require("../../tree/latexParser/latexParse");
8
+ var numberNode_1 = require("../../tree/nodes/numbers/numberNode");
9
+ var multiplyNode_1 = require("../../tree/nodes/operators/multiplyNode");
10
+ var powerNode_1 = require("../../tree/nodes/operators/powerNode");
11
+ var getDistinctQuestions_1 = require("../utils/getDistinctQuestions");
12
+ /**
13
+ * a*10^x vers décimal
14
+ * */
15
+ exports.scientificToDecimal = {
16
+ id: "scientificToDecimal",
17
+ connector: "=",
18
+ instruction: "Donner l'écriture décimale de :",
19
+ label: "Ecriture décimale de $a\\times 10^x",
20
+ levels: ["5", "4", "3", "2"],
21
+ section: "Puissances",
22
+ isSingleStep: true,
23
+ generator: function (nb) { return (0, getDistinctQuestions_1.getDistinctQuestions)(getScientificToDecimalQuestion, nb); }
24
+ };
25
+ function getScientificToDecimalQuestion() {
26
+ var randPower = (0, randint_1.randint)(-6, 8);
27
+ var int = integer_1.IntegerConstructor.random((0, randint_1.randint)(1, 4));
28
+ var fracPart = decimal_1.DecimalConstructor.randomFracPart((0, randint_1.randint)(0, 4));
29
+ var randDecimal = decimal_1.DecimalConstructor.fromParts(int + "", fracPart);
30
+ var statement = new multiplyNode_1.MultiplyNode(new numberNode_1.NumberNode(randDecimal.value), new powerNode_1.PowerNode(new numberNode_1.NumberNode(10), new numberNode_1.NumberNode(randPower)));
31
+ var answerTree = randDecimal.multiplyByPowerOfTen(randPower).toTree();
32
+ var question = {
33
+ statement: (0, latexParse_1.latexParse)(statement),
34
+ answer: (0, latexParse_1.latexParse)(answerTree)
35
+ };
36
+ return question;
37
+ }
38
+ exports.getScientificToDecimalQuestion = getScientificToDecimalQuestion;
@@ -0,0 +1,44 @@
1
+ import { randint } from "../../mathutils/random/randint";
2
+ import { DecimalConstructor } from "../../numbers/decimals/decimal";
3
+ import { IntegerConstructor } from "../../numbers/integer/integer";
4
+ import { Power } from "../../numbers/integer/power";
5
+ import { latexParse } from "../../tree/latexParser/latexParse";
6
+ import { NumberNode } from "../../tree/nodes/numbers/numberNode";
7
+ import { FractionNode } from "../../tree/nodes/operators/fractionNode";
8
+ import { MultiplyNode } from "../../tree/nodes/operators/multiplyNode";
9
+ import { PowerNode } from "../../tree/nodes/operators/powerNode";
10
+ import { Exercise, Question } from "../exercise";
11
+ import { getDistinctQuestions } from "../utils/getDistinctQuestions";
12
+
13
+ /**
14
+ * a*10^x vers décimal
15
+ * */
16
+
17
+ export const scientificToDecimal: Exercise = {
18
+ id: "scientificToDecimal",
19
+ connector: "=",
20
+ instruction: "Donner l'écriture décimale de :",
21
+ label: "Ecriture décimale de $a\\times 10^x",
22
+ levels: ["5", "4", "3", "2"],
23
+ section: "Puissances",
24
+ isSingleStep: true,
25
+ generator: (nb: number) => getDistinctQuestions(getScientificToDecimalQuestion, nb),
26
+ };
27
+
28
+ export function getScientificToDecimalQuestion(): Question {
29
+ const randPower = randint(-6, 8);
30
+ const int = IntegerConstructor.random(randint(1, 4));
31
+ const fracPart = DecimalConstructor.randomFracPart(randint(0, 4));
32
+ const randDecimal = DecimalConstructor.fromParts(int + "", fracPart);
33
+ const statement = new MultiplyNode(
34
+ new NumberNode(randDecimal.value),
35
+ new PowerNode(new NumberNode(10), new NumberNode(randPower))
36
+ );
37
+ const answerTree = randDecimal.multiplyByPowerOfTen(randPower).toTree();
38
+
39
+ const question: Question = {
40
+ statement: latexParse(statement),
41
+ answer: latexParse(answerTree),
42
+ };
43
+ return question;
44
+ }
@@ -1,17 +1,16 @@
1
1
  "use strict";
2
- /**
3
- * type (ax+b)(cx+d) ± (ax+b)(ex+f)
4
- */
5
2
  exports.__esModule = true;
6
3
  exports.getSimplifySquareRoot = exports.simplifySquareRoot = void 0;
7
4
  var squareRoot_1 = require("../../numbers/reals/squareRoot");
8
5
  var latexParse_1 = require("../../tree/latexParser/latexParse");
9
6
  var getDistinctQuestions_1 = require("../utils/getDistinctQuestions");
10
7
  exports.simplifySquareRoot = {
8
+ id: "simplifySqrt",
11
9
  connector: "=",
12
10
  instruction: "Simplifier :",
13
11
  label: "Simplification de racines carrées",
14
12
  levels: ["3", "2", "1"],
13
+ isSingleStep: false,
15
14
  section: "Racines carrées",
16
15
  generator: function (nb) { return (0, getDistinctQuestions_1.getDistinctQuestions)(getSimplifySquareRoot, nb); }
17
16
  };
@@ -4,10 +4,12 @@ import { Exercise, Question } from "../exercise";
4
4
  import { getDistinctQuestions } from "../utils/getDistinctQuestions";
5
5
 
6
6
  export const simplifySquareRoot: Exercise = {
7
+ id: "simplifySqrt",
7
8
  connector: "=",
8
9
  instruction: "Simplifier :",
9
10
  label: "Simplification de racines carrées",
10
11
  levels: ["3", "2", "1"],
12
+ isSingleStep: false,
11
13
  section: "Racines carrées",
12
14
  generator: (nb: number) => getDistinctQuestions(getSimplifySquareRoot, nb),
13
15
  };
package/src/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  exports.__esModule = true;
3
- var equationType1Exercise_1 = require("./exercises/calculLitteral/equation/equationType1Exercise");
4
- var equationType2Exercise_1 = require("./exercises/calculLitteral/equation/equationType2Exercise");
5
- var equationType3Exercise_1 = require("./exercises/calculLitteral/equation/equationType3Exercise");
6
- var equationType4Exercise_1 = require("./exercises/calculLitteral/equation/equationType4Exercise");
7
- console.log(equationType1Exercise_1.equationType1Exercise.generator(10));
8
- console.log(equationType2Exercise_1.equationType2Exercise.generator(10));
9
- console.log(equationType3Exercise_1.equationType3Exercise.generator(10));
10
- console.log(equationType4Exercise_1.equationType4Exercise.generator(10));
3
+ exports.exercises = void 0;
4
+ var exercises_1 = require("./exercises/exercises");
5
+ exports.exercises = exercises_1.exercises;
6
+ var scientificToDecimal_1 = require("./exercises/powers/scientificToDecimal");
7
+ // exercises.forEach((exo) => {
8
+ // console.log(exo.instruction, exo.generator(10));
9
+ // });
10
+ console.log(scientificToDecimal_1.scientificToDecimal);
package/src/index.ts CHANGED
@@ -1,19 +1,8 @@
1
- import { allIdentities } from "./exercises/calculLitteral/distributivity/allIdentities";
2
- import { doubleDistributivity } from "./exercises/calculLitteral/distributivity/doubleDistributivity";
3
- import { simpleDistributivity } from "./exercises/calculLitteral/distributivity/simpleDistributivity";
4
- import { equationType1Exercise } from "./exercises/calculLitteral/equation/equationType1Exercise";
5
- import { equationType2Exercise } from "./exercises/calculLitteral/equation/equationType2Exercise";
6
- import { equationType3Exercise } from "./exercises/calculLitteral/equation/equationType3Exercise";
7
- import { equationType4Exercise } from "./exercises/calculLitteral/equation/equationType4Exercise";
8
- import { factoType1Exercise } from "./exercises/calculLitteral/factorisation/factoType1Exercise";
9
1
  import { exercises } from "./exercises/exercises";
10
- import { simplifySquareRoot } from "./exercises/squareRoots/simpifySquareRoot";
11
- import { randint } from "./mathutils/random/randint";
12
- import { Rational } from "./numbers/rationals/rational";
13
- import { SquareRoot } from "./numbers/reals/squareRoot";
14
- import { Affine } from "./polynomials/affine";
15
- import { Polynomial } from "./polynomials/polynomial";
16
- import { latexParse } from "./tree/latexParser/latexParse";
17
- import { VariableNode } from "./tree/nodes/variables/variableNode";
2
+ import { scientificToDecimal } from "./exercises/powers/scientificToDecimal";
18
3
 
4
+ console.log(scientificToDecimal.generator(10));
5
+ // exercises.forEach((exo) => {
6
+ // console.log(exo.instruction, exo.generator(10));
7
+ // });
19
8
  export { exercises };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.coprimesOf = void 0;
4
+ var gcd_1 = require("./gcd");
5
+ var coprimesOf = function (nb) {
6
+ var coprimes = [];
7
+ for (var i = 2; i <= nb; i++) {
8
+ if ((0, gcd_1.gcd)(nb, i) === 1)
9
+ coprimes.push(i);
10
+ }
11
+ return coprimes;
12
+ };
13
+ exports.coprimesOf = coprimesOf;
@@ -0,0 +1,9 @@
1
+ import { gcd } from "./gcd";
2
+
3
+ export const coprimesOf = (nb: number) => {
4
+ let coprimes = [];
5
+ for (let i = 2; i <= nb; i++) {
6
+ if (gcd(nb, i) === 1) coprimes.push(i);
7
+ }
8
+ return coprimes;
9
+ };
@@ -0,0 +1,7 @@
1
+ export const dividersOf = (nb: number) => {
2
+ let divisors = [];
3
+ for (let i = 1; i <= nb; i++) {
4
+ if (nb % i === 0) divisors.push(i);
5
+ }
6
+ return divisors;
7
+ };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.lcd = void 0;
4
+ function lcd(a, b) {
5
+ var max = Math.max(a, b);
6
+ for (var i = max; i < a * b; i++) {
7
+ if (i % a === 0 && i % b === 0)
8
+ return i;
9
+ }
10
+ return a * b;
11
+ }
12
+ exports.lcd = lcd;
@@ -0,0 +1,7 @@
1
+ export function lcd(a: number, b: number) {
2
+ const max = Math.max(a, b);
3
+ for (let i = max; i < a * b; i++) {
4
+ if (i % a === 0 && i % b === 0) return i;
5
+ }
6
+ return a * b;
7
+ }
@@ -0,0 +1,9 @@
1
+ import { gcd } from "./gcd";
2
+
3
+ export const nonCoprimesOf = (nb: number) => {
4
+ let nonCoprimes = [];
5
+ for (let i = 1; i <= nb; i++) {
6
+ if (gcd(nb, i) !== 1) nonCoprimes.push(i);
7
+ }
8
+ return nonCoprimes;
9
+ };
@@ -0,0 +1,12 @@
1
+ import { dividersOf } from "./dividersOf";
2
+
3
+ export const nonDivisorOf = (nb: number) => {
4
+ let nonDividers = [];
5
+ let dividers = dividersOf(nb);
6
+
7
+ for (let i = 2; i < nb; i++) {
8
+ if (nb % i !== 0) nonDividers.push(i);
9
+ }
10
+
11
+ return nonDividers;
12
+ };
@@ -0,0 +1,10 @@
1
+ export const decimalPartLengthOf = (x: number) => {
2
+ function hasFraction(x: number) {
3
+ return Math.abs(Math.round(x) - x) > 1e-10;
4
+ }
5
+
6
+ let count = 0;
7
+ // multiply by increasing powers of 10 until the fractional part is ~ 0
8
+ while (hasFraction(x * 10 ** count) && isFinite(10 ** count)) count++;
9
+ return count;
10
+ };
@@ -1,9 +1,18 @@
1
1
  "use strict";
2
2
  exports.__esModule = true;
3
3
  exports.randint = void 0;
4
- var randint = function (a, b) {
4
+ /**
5
+ * @returns random [[a, b[[
6
+ */
7
+ var randint = function (a, b, excludes) {
5
8
  if (b === undefined)
6
9
  return Math.floor(Math.random() * a);
7
- return a + Math.floor(Math.random() * (b - a));
10
+ if (!excludes)
11
+ return a + Math.floor(Math.random() * (b - a));
12
+ var res;
13
+ do {
14
+ res = a + Math.floor(Math.random() * (b - a));
15
+ } while (excludes.includes(res));
16
+ return res;
8
17
  };
9
18
  exports.randint = randint;
@@ -1,4 +1,12 @@
1
- export const randint = (a: number, b?: number) => {
1
+ /**
2
+ * @returns random [[a, b[[
3
+ */
4
+ export const randint = (a: number, b?: number, excludes?: number[]): number => {
2
5
  if (b === undefined) return Math.floor(Math.random() * a);
3
- return a + Math.floor(Math.random() * (b - a));
6
+ if (!excludes) return a + Math.floor(Math.random() * (b - a));
7
+ let res;
8
+ do {
9
+ res = a + Math.floor(Math.random() * (b - a));
10
+ } while (excludes.includes(res));
11
+ return res;
4
12
  };
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.Decimal = exports.DecimalConstructor = void 0;
4
+ var randint_1 = require("../../mathutils/random/randint");
5
+ var numberNode_1 = require("../../tree/nodes/numbers/numberNode");
6
+ var integer_1 = require("../integer/integer");
7
+ var nombre_1 = require("../nombre");
8
+ var DecimalConstructor = /** @class */ (function () {
9
+ function DecimalConstructor() {
10
+ }
11
+ DecimalConstructor.randomFracPart = function (precision) {
12
+ var decimals = "";
13
+ for (var i = 0; i < precision; i++) {
14
+ decimals += (0, randint_1.randint)(i === precision - 1 ? 1 : 0, 10);
15
+ }
16
+ return decimals;
17
+ };
18
+ DecimalConstructor.random = function (min, max, precision) {
19
+ var int = (0, randint_1.randint)(min, max) + "";
20
+ var decimals = DecimalConstructor.randomFracPart(precision);
21
+ return DecimalConstructor.fromParts(int, decimals);
22
+ };
23
+ DecimalConstructor.fromParts = function (intPart, decimalPart) {
24
+ return new Decimal(Number("" + intPart + "." + decimalPart));
25
+ };
26
+ return DecimalConstructor;
27
+ }());
28
+ exports.DecimalConstructor = DecimalConstructor;
29
+ var Decimal = /** @class */ (function () {
30
+ function Decimal(value) {
31
+ this.type = nombre_1.NumberType.Decimal;
32
+ this.value = value;
33
+ this.tex = value + "";
34
+ var _a = (value + "").split("."), intPartString = _a[0], decimalPartString = _a[1];
35
+ this.intPart = Number(intPartString);
36
+ this.decimalPart = decimalPartString || "";
37
+ this.precision = this.decimalPart.length;
38
+ }
39
+ /**
40
+ *
41
+ * @param precision 0 = unité, 1 = dizieme, ... , -1 : dizaine
42
+ * @returns
43
+ */
44
+ Decimal.prototype.round = function (precision) {
45
+ var intPartString = this.intPart + "";
46
+ if (precision < 0) {
47
+ if (precision < -intPartString.length)
48
+ throw Error("can't round to higher precision");
49
+ return new integer_1.Integer(this.intPart).round(-precision);
50
+ }
51
+ if (precision > this.precision)
52
+ throw Error("can't round to higher precision");
53
+ if (precision === this.precision)
54
+ return this;
55
+ var newFracPart = "", newIntPart = "";
56
+ var shouldRoundUp = Number(this.decimalPart[precision]) > 4;
57
+ if (shouldRoundUp) {
58
+ var retenue = true;
59
+ var i = precision - 1;
60
+ while (retenue) {
61
+ if (i > -1) {
62
+ var nb = (Number(this.decimalPart[i]) + 1) % 10;
63
+ if (nb || newFracPart) {
64
+ newFracPart = nb.toString() + newFracPart;
65
+ }
66
+ if (nb !== 0) {
67
+ retenue = false;
68
+ for (var j = i - 1; j > -1; j--) {
69
+ newFracPart = this.decimalPart[j] + newFracPart;
70
+ }
71
+ newIntPart = intPartString;
72
+ }
73
+ else
74
+ i--;
75
+ }
76
+ else {
77
+ var nb = (Number(intPartString[i + intPartString.length]) + 1) % 10;
78
+ newIntPart = nb + "" + newIntPart;
79
+ if (nb !== 0) {
80
+ retenue = false;
81
+ for (var j = i + intPartString.length - 1; j > -1; j--) {
82
+ newIntPart = intPartString[j] + newIntPart;
83
+ }
84
+ }
85
+ else
86
+ i--;
87
+ }
88
+ }
89
+ }
90
+ else {
91
+ var retenue = true;
92
+ var i = precision - 1;
93
+ while (retenue) {
94
+ if (i > -1) {
95
+ var nb = Number(this.decimalPart[i]);
96
+ if (nb || newFracPart) {
97
+ newFracPart = nb.toString() + newFracPart;
98
+ }
99
+ if (nb !== 0) {
100
+ retenue = false;
101
+ for (var j = i - 1; j > -1; j--) {
102
+ newFracPart = this.decimalPart[j] + newFracPart;
103
+ }
104
+ newIntPart = intPartString;
105
+ }
106
+ else
107
+ i--;
108
+ }
109
+ else {
110
+ newIntPart = intPartString;
111
+ retenue = false;
112
+ }
113
+ }
114
+ }
115
+ return DecimalConstructor.fromParts(newIntPart, newFracPart);
116
+ };
117
+ Decimal.prototype.multiplyByPowerOfTen = function (power) {
118
+ var newIntPart = "", newFracPart = "";
119
+ if (power > -1) {
120
+ newIntPart = this.intPart + "";
121
+ for (var i = 0; i < power; i++) {
122
+ newIntPart += i > this.decimalPart.length - 1 ? "0" : this.decimalPart[i];
123
+ }
124
+ newFracPart = this.decimalPart.slice(power);
125
+ }
126
+ else {
127
+ var intPartString = this.intPart + "";
128
+ newFracPart = this.decimalPart;
129
+ for (var i = intPartString.length - 1; i > intPartString.length - 1 + power; i--) {
130
+ newFracPart = (i < 0 ? "0" : intPartString[i]) + newFracPart;
131
+ }
132
+ if (power + intPartString.length < 1)
133
+ newIntPart = "0";
134
+ else
135
+ newIntPart = intPartString.slice(0, power + intPartString.length);
136
+ }
137
+ return DecimalConstructor.fromParts(newIntPart, newFracPart);
138
+ };
139
+ Decimal.prototype.toTree = function () {
140
+ return new numberNode_1.NumberNode(this.value);
141
+ };
142
+ return Decimal;
143
+ }());
144
+ exports.Decimal = Decimal;