math-exercises 1.3.2 → 1.3.4
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/README.md +71 -71
- package/lib/exercises/calcul/addAndSub.js +40 -39
- package/lib/exercises/calcul/fractions/fractionAndIntegerDivision.js +35 -34
- package/lib/exercises/calcul/fractions/fractionAndIntegerProduct.js +31 -31
- package/lib/exercises/calcul/fractions/fractionAndIntegerSum.js +32 -31
- package/lib/exercises/calcul/fractions/fractionsDivision.js +29 -28
- package/lib/exercises/calcul/fractions/fractionsProduct.js +29 -28
- package/lib/exercises/calcul/fractions/fractionsSum.js +29 -28
- package/lib/exercises/calcul/fractions/simplifyFraction.js +25 -24
- package/lib/exercises/calcul/operationsPriorities.js +88 -88
- package/lib/exercises/calcul/rounding/rounding.js +86 -85
- package/lib/exercises/calculLitteral/distributivity/allIdentities.js +27 -27
- package/lib/exercises/calculLitteral/distributivity/doubleDistributivity.js +31 -30
- package/lib/exercises/calculLitteral/distributivity/firstIdentity.js +32 -31
- package/lib/exercises/calculLitteral/distributivity/secondIdentity.js +33 -32
- package/lib/exercises/calculLitteral/distributivity/simpleDistributivity.js +33 -32
- package/lib/exercises/calculLitteral/distributivity/thirdIdentity.js +32 -31
- package/lib/exercises/calculLitteral/equation/equationType1Exercise.js +38 -37
- package/lib/exercises/calculLitteral/equation/equationType2Exercise.js +41 -40
- package/lib/exercises/calculLitteral/equation/equationType3Exercise.js +42 -41
- package/lib/exercises/calculLitteral/equation/equationType4Exercise.js +44 -43
- package/lib/exercises/calculLitteral/factorisation/factoType1Exercise.js +39 -38
- package/lib/exercises/exercise.js +7 -7
- package/lib/exercises/exercises.js +85 -95
- package/lib/exercises/powers/powersDivision.js +45 -44
- package/lib/exercises/powers/powersOfTenToDecimal.js +33 -32
- package/lib/exercises/powers/powersPower.js +44 -43
- package/lib/exercises/powers/powersProduct.js +45 -44
- package/lib/exercises/powers/scientificToDecimal.js +38 -37
- package/lib/exercises/squareRoots/simpifySquareRoot.js +28 -27
- package/lib/exercises/utils/getDistinctQuestions.js +15 -15
- package/lib/geometry/point.js +1 -27
- package/lib/index.js +5 -9
- package/lib/mathutils/arithmetic/coprimesOf.js +13 -13
- package/lib/mathutils/arithmetic/dividersOf.js +12 -12
- package/lib/mathutils/arithmetic/gcd.js +7 -7
- package/lib/mathutils/arithmetic/isSquare.js +7 -7
- package/lib/mathutils/arithmetic/lcd.js +12 -12
- package/lib/mathutils/arithmetic/nonCoprimesOf.js +13 -13
- package/lib/mathutils/arithmetic/nonDividersOf.js +14 -14
- package/lib/mathutils/arithmetic/primeFactors.js +22 -22
- package/lib/mathutils/decimals/decimalPartLengthOf.js +14 -14
- package/lib/mathutils/random/randint.js +18 -18
- package/lib/mathutils/round.js +8 -8
- package/lib/numbers/decimals/decimal.js +140 -140
- package/lib/numbers/epsilon.js +10 -10
- package/lib/numbers/integer/integer.js +68 -68
- package/lib/numbers/integer/power.js +52 -52
- package/lib/numbers/nombre.js +10 -10
- package/lib/numbers/rationals/rational.js +113 -113
- package/lib/numbers/reals/real.js +16 -16
- package/lib/numbers/reals/squareRoot.js +63 -63
- package/lib/polynomials/affine.js +42 -42
- package/lib/polynomials/polynomial.js +125 -125
- package/lib/sets/discreteSet.js +28 -28
- package/lib/sets/emptySet.js +6 -6
- package/lib/sets/intervals/intervals.js +108 -108
- package/lib/sets/intervals/union.js +1 -1
- package/lib/sets/mathSet.js +10 -10
- package/lib/sets/mathSetInterface.js +2 -2
- package/lib/tree/nodes/functions/functionNode.js +18 -18
- package/lib/tree/nodes/functions/oppositeNode.js +13 -26
- package/lib/tree/nodes/functions/sqrtNode.js +15 -18
- package/lib/tree/nodes/node.js +10 -10
- package/lib/tree/nodes/numbers/numberNode.js +15 -18
- package/lib/tree/nodes/operators/addNode.js +15 -19
- package/lib/tree/nodes/operators/divideNode.js +17 -34
- package/lib/tree/nodes/operators/equalNode.js +13 -16
- package/lib/tree/nodes/operators/fractionNode.js +17 -20
- package/lib/tree/nodes/operators/multiplyNode.js +13 -36
- package/lib/tree/nodes/operators/operatorNode.js +35 -35
- package/lib/tree/nodes/operators/powerNode.js +13 -33
- package/lib/tree/nodes/operators/substractNode.js +13 -24
- package/lib/tree/nodes/variables/variableNode.js +16 -19
- package/lib/tree/parsers/derivateParser.js +60 -62
- package/lib/tree/parsers/latexParser.js +117 -110
- package/lib/utils/coin.js +7 -7
- package/lib/utils/random.js +7 -7
- package/lib/utils/shuffle.js +15 -15
- package/package.json +41 -38
- package/lib/exercises/calcul/operations/operationsPriorities.js +0 -98
- package/lib/exercises/calcul/operations/operationsPrioritiesWithoutRelative.js +0 -111
- package/lib/exercises/geometry/cartesian/midpoint.js +0 -29
- package/lib/exercises/geometry/vectors/scalarProductViaCoords.js +0 -28
- package/lib/exercises/geometry/vectors/scalarProductViaNorms.js +0 -27
- package/lib/geometry/vector.js +0 -31
- package/lib/mathutils/random/randTupleInt.js +0 -30
- package/lib/tree/parsers/simplify.js +0 -51
- package/lib/utils/arrayEqual.js +0 -13
|
@@ -1,44 +1,45 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPowersProductQuestion = exports.powersProduct = exports.powersOfTenProduct = void 0;
|
|
4
|
-
const randint_1 = require("../../mathutils/random/randint");
|
|
5
|
-
const power_1 = require("../../numbers/integer/power");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPowersProductQuestion = exports.powersProduct = exports.powersOfTenProduct = void 0;
|
|
4
|
+
const randint_1 = require("../../mathutils/random/randint");
|
|
5
|
+
const power_1 = require("../../numbers/integer/power");
|
|
6
|
+
const latexParser_1 = require("../../tree/parsers/latexParser");
|
|
7
|
+
const numberNode_1 = require("../../tree/nodes/numbers/numberNode");
|
|
8
|
+
const multiplyNode_1 = require("../../tree/nodes/operators/multiplyNode");
|
|
9
|
+
const powerNode_1 = require("../../tree/nodes/operators/powerNode");
|
|
10
|
+
const 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: "Puissances",
|
|
21
|
+
isSingleStep: true,
|
|
22
|
+
generator: (nb) => (0, getDistinctQuestions_1.getDistinctQuestions)(() => 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: (nb) => (0, getDistinctQuestions_1.getDistinctQuestions)(getPowersProductQuestion, nb),
|
|
33
|
+
};
|
|
34
|
+
function getPowersProductQuestion(useOnlyPowersOfTen = false) {
|
|
35
|
+
const a = useOnlyPowersOfTen ? 10 : (0, randint_1.randint)(-11, 11);
|
|
36
|
+
const [b, c] = [1, 2].map((el) => (0, randint_1.randint)(-11, 11));
|
|
37
|
+
const 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)));
|
|
38
|
+
const answerTree = new power_1.Power(a, b + c).simplify();
|
|
39
|
+
const question = {
|
|
40
|
+
startStatement: (0, latexParser_1.latexParser)(statement),
|
|
41
|
+
answer: (0, latexParser_1.latexParser)(answerTree),
|
|
42
|
+
};
|
|
43
|
+
return question;
|
|
44
|
+
}
|
|
45
|
+
exports.getPowersProductQuestion = getPowersProductQuestion;
|
|
@@ -1,37 +1,38 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getScientificToDecimalQuestion = exports.scientificToDecimal = void 0;
|
|
4
|
-
const randint_1 = require("../../mathutils/random/randint");
|
|
5
|
-
const decimal_1 = require("../../numbers/decimals/decimal");
|
|
6
|
-
const integer_1 = require("../../numbers/integer/integer");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getScientificToDecimalQuestion = exports.scientificToDecimal = void 0;
|
|
4
|
+
const randint_1 = require("../../mathutils/random/randint");
|
|
5
|
+
const decimal_1 = require("../../numbers/decimals/decimal");
|
|
6
|
+
const integer_1 = require("../../numbers/integer/integer");
|
|
7
|
+
const latexParser_1 = require("../../tree/parsers/latexParser");
|
|
8
|
+
const numberNode_1 = require("../../tree/nodes/numbers/numberNode");
|
|
9
|
+
const multiplyNode_1 = require("../../tree/nodes/operators/multiplyNode");
|
|
10
|
+
const powerNode_1 = require("../../tree/nodes/operators/powerNode");
|
|
11
|
+
const 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: (nb) => (0, getDistinctQuestions_1.getDistinctQuestions)(getScientificToDecimalQuestion, nb),
|
|
24
|
+
};
|
|
25
|
+
function getScientificToDecimalQuestion() {
|
|
26
|
+
const randPower = (0, randint_1.randint)(-6, 8);
|
|
27
|
+
const int = integer_1.IntegerConstructor.random((0, randint_1.randint)(1, 4));
|
|
28
|
+
const fracPart = decimal_1.DecimalConstructor.randomFracPart((0, randint_1.randint)(0, 4));
|
|
29
|
+
const randDecimal = decimal_1.DecimalConstructor.fromParts(int + "", fracPart);
|
|
30
|
+
const 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
|
+
const answerTree = randDecimal.multiplyByPowerOfTen(randPower).toTree();
|
|
32
|
+
const question = {
|
|
33
|
+
startStatement: (0, latexParser_1.latexParser)(statement),
|
|
34
|
+
answer: (0, latexParser_1.latexParser)(answerTree),
|
|
35
|
+
};
|
|
36
|
+
return question;
|
|
37
|
+
}
|
|
38
|
+
exports.getScientificToDecimalQuestion = getScientificToDecimalQuestion;
|
|
@@ -1,27 +1,28 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSimplifySquareRoot = exports.simplifySquareRoot = void 0;
|
|
4
|
-
const squareRoot_1 = require("../../numbers/reals/squareRoot");
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSimplifySquareRoot = exports.simplifySquareRoot = void 0;
|
|
4
|
+
const squareRoot_1 = require("../../numbers/reals/squareRoot");
|
|
5
|
+
const latexParser_1 = require("../../tree/parsers/latexParser");
|
|
6
|
+
const getDistinctQuestions_1 = require("../utils/getDistinctQuestions");
|
|
7
|
+
exports.simplifySquareRoot = {
|
|
8
|
+
id: "simplifySqrt",
|
|
9
|
+
connector: "=",
|
|
10
|
+
instruction: "Simplifier :",
|
|
11
|
+
label: "Simplification de racines carrées",
|
|
12
|
+
levels: ["3", "2", "1"],
|
|
13
|
+
isSingleStep: false,
|
|
14
|
+
section: "Racines carrées",
|
|
15
|
+
generator: (nb) => (0, getDistinctQuestions_1.getDistinctQuestions)(getSimplifySquareRoot, nb),
|
|
16
|
+
};
|
|
17
|
+
function getSimplifySquareRoot() {
|
|
18
|
+
const squareRoot = squareRoot_1.SquareRootConstructor.randomSimplifiable({
|
|
19
|
+
allowPerfectSquare: false,
|
|
20
|
+
maxSquare: 11,
|
|
21
|
+
});
|
|
22
|
+
const question = {
|
|
23
|
+
startStatement: (0, latexParser_1.latexParser)(squareRoot.toTree()),
|
|
24
|
+
answer: (0, latexParser_1.latexParser)(squareRoot.simplify().toTree()),
|
|
25
|
+
};
|
|
26
|
+
return question;
|
|
27
|
+
}
|
|
28
|
+
exports.getSimplifySquareRoot = getSimplifySquareRoot;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDistinctQuestions = void 0;
|
|
4
|
-
const getDistinctQuestions = (generator, nb) => {
|
|
5
|
-
const res = [];
|
|
6
|
-
for (let i = 0; i < nb; i++) {
|
|
7
|
-
let question;
|
|
8
|
-
do {
|
|
9
|
-
question = generator();
|
|
10
|
-
} while (res.some((q) => q.
|
|
11
|
-
res.push(question);
|
|
12
|
-
}
|
|
13
|
-
return res;
|
|
14
|
-
};
|
|
15
|
-
exports.getDistinctQuestions = getDistinctQuestions;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDistinctQuestions = void 0;
|
|
4
|
+
const getDistinctQuestions = (generator, nb) => {
|
|
5
|
+
const res = [];
|
|
6
|
+
for (let i = 0; i < nb; i++) {
|
|
7
|
+
let question;
|
|
8
|
+
do {
|
|
9
|
+
question = generator();
|
|
10
|
+
} while (res.some((q) => q.startStatement === question.startStatement));
|
|
11
|
+
res.push(question);
|
|
12
|
+
}
|
|
13
|
+
return res;
|
|
14
|
+
};
|
|
15
|
+
exports.getDistinctQuestions = getDistinctQuestions;
|
package/lib/geometry/point.js
CHANGED
|
@@ -1,27 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Point = exports.PointConstructor = void 0;
|
|
4
|
-
const numberNode_1 = require("../tree/nodes/numbers/numberNode");
|
|
5
|
-
const addNode_1 = require("../tree/nodes/operators/addNode");
|
|
6
|
-
const fractionNode_1 = require("../tree/nodes/operators/fractionNode");
|
|
7
|
-
const simplify_1 = require("../tree/parsers/simplify");
|
|
8
|
-
class PointConstructor {
|
|
9
|
-
}
|
|
10
|
-
exports.PointConstructor = PointConstructor;
|
|
11
|
-
class Point {
|
|
12
|
-
constructor(name, x, y) {
|
|
13
|
-
this.name = name;
|
|
14
|
-
this.x = x;
|
|
15
|
-
this.y = y;
|
|
16
|
-
}
|
|
17
|
-
toTex() {
|
|
18
|
-
return `${this.name}`;
|
|
19
|
-
}
|
|
20
|
-
toTexWithCoords() {
|
|
21
|
-
return `${this.name}\\left(${this.x.toTex()}; ${this.y.toTex()}\\right)`;
|
|
22
|
-
}
|
|
23
|
-
midpoint(B, name = 'I') {
|
|
24
|
-
return new Point(name, (0, simplify_1.simplifyNode)(new fractionNode_1.FractionNode(new addNode_1.AddNode(this.x, B.x), new numberNode_1.NumberNode(2))), (0, simplify_1.simplifyNode)(new fractionNode_1.FractionNode(new addNode_1.AddNode(this.y, B.y), new numberNode_1.NumberNode(2))));
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
exports.Point = Point;
|
|
1
|
+
"use strict";
|
package/lib/index.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.exercises = void 0;
|
|
4
|
-
const exercises_1 = require("./exercises/exercises");
|
|
5
|
-
Object.defineProperty(exports, "exercises", { enumerable: true, get: function () { return exercises_1.exercises; } });
|
|
6
|
-
// import { simplify } from './tree/parsers/simplify';
|
|
7
|
-
exercises_1.exercises.forEach((exo) => {
|
|
8
|
-
console.log(exo.instruction, exo.generator(10));
|
|
9
|
-
});
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.exercises = void 0;
|
|
4
|
+
const exercises_1 = require("./exercises/exercises");
|
|
5
|
+
Object.defineProperty(exports, "exercises", { enumerable: true, get: function () { return exercises_1.exercises; } });
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.coprimesOf = void 0;
|
|
4
|
-
const gcd_1 = require("./gcd");
|
|
5
|
-
const coprimesOf = (nb) => {
|
|
6
|
-
let coprimes = [];
|
|
7
|
-
for (let 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;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.coprimesOf = void 0;
|
|
4
|
+
const gcd_1 = require("./gcd");
|
|
5
|
+
const coprimesOf = (nb) => {
|
|
6
|
+
let coprimes = [];
|
|
7
|
+
for (let 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;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dividersOf = void 0;
|
|
4
|
-
const dividersOf = (nb) => {
|
|
5
|
-
let divisors = [];
|
|
6
|
-
for (let i = 1; i <= nb; i++) {
|
|
7
|
-
if (nb % i === 0)
|
|
8
|
-
divisors.push(i);
|
|
9
|
-
}
|
|
10
|
-
return divisors;
|
|
11
|
-
};
|
|
12
|
-
exports.dividersOf = dividersOf;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dividersOf = void 0;
|
|
4
|
+
const dividersOf = (nb) => {
|
|
5
|
+
let divisors = [];
|
|
6
|
+
for (let i = 1; i <= nb; i++) {
|
|
7
|
+
if (nb % i === 0)
|
|
8
|
+
divisors.push(i);
|
|
9
|
+
}
|
|
10
|
+
return divisors;
|
|
11
|
+
};
|
|
12
|
+
exports.dividersOf = dividersOf;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.gcd = void 0;
|
|
4
|
-
function gcd(a, b) {
|
|
5
|
-
return b ? gcd(b, a % b) : a;
|
|
6
|
-
}
|
|
7
|
-
exports.gcd = gcd;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.gcd = void 0;
|
|
4
|
+
function gcd(a, b) {
|
|
5
|
+
return b ? gcd(b, a % b) : a;
|
|
6
|
+
}
|
|
7
|
+
exports.gcd = gcd;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isSquare = void 0;
|
|
4
|
-
const isSquare = (a) => {
|
|
5
|
-
return a > 0 && Math.sqrt(a) % 1 === 0;
|
|
6
|
-
};
|
|
7
|
-
exports.isSquare = isSquare;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isSquare = void 0;
|
|
4
|
+
const isSquare = (a) => {
|
|
5
|
+
return a > 0 && Math.sqrt(a) % 1 === 0;
|
|
6
|
+
};
|
|
7
|
+
exports.isSquare = isSquare;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.lcd = void 0;
|
|
4
|
-
function lcd(a, b) {
|
|
5
|
-
const max = Math.max(a, b);
|
|
6
|
-
for (let 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;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lcd = void 0;
|
|
4
|
+
function lcd(a, b) {
|
|
5
|
+
const max = Math.max(a, b);
|
|
6
|
+
for (let 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;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.nonCoprimesOf = void 0;
|
|
4
|
-
const gcd_1 = require("./gcd");
|
|
5
|
-
const nonCoprimesOf = (nb) => {
|
|
6
|
-
let nonCoprimes = [];
|
|
7
|
-
for (let i = 1; i <= nb; i++) {
|
|
8
|
-
if ((0, gcd_1.gcd)(nb, i) !== 1)
|
|
9
|
-
nonCoprimes.push(i);
|
|
10
|
-
}
|
|
11
|
-
return nonCoprimes;
|
|
12
|
-
};
|
|
13
|
-
exports.nonCoprimesOf = nonCoprimesOf;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.nonCoprimesOf = void 0;
|
|
4
|
+
const gcd_1 = require("./gcd");
|
|
5
|
+
const nonCoprimesOf = (nb) => {
|
|
6
|
+
let nonCoprimes = [];
|
|
7
|
+
for (let i = 1; i <= nb; i++) {
|
|
8
|
+
if ((0, gcd_1.gcd)(nb, i) !== 1)
|
|
9
|
+
nonCoprimes.push(i);
|
|
10
|
+
}
|
|
11
|
+
return nonCoprimes;
|
|
12
|
+
};
|
|
13
|
+
exports.nonCoprimesOf = nonCoprimesOf;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.nonDivisorOf = void 0;
|
|
4
|
-
const dividersOf_1 = require("./dividersOf");
|
|
5
|
-
const nonDivisorOf = (nb) => {
|
|
6
|
-
let nonDividers = [];
|
|
7
|
-
let dividers = (0, dividersOf_1.dividersOf)(nb);
|
|
8
|
-
for (let i = 2; i < nb; i++) {
|
|
9
|
-
if (nb % i !== 0)
|
|
10
|
-
nonDividers.push(i);
|
|
11
|
-
}
|
|
12
|
-
return nonDividers;
|
|
13
|
-
};
|
|
14
|
-
exports.nonDivisorOf = nonDivisorOf;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.nonDivisorOf = void 0;
|
|
4
|
+
const dividersOf_1 = require("./dividersOf");
|
|
5
|
+
const nonDivisorOf = (nb) => {
|
|
6
|
+
let nonDividers = [];
|
|
7
|
+
let dividers = (0, dividersOf_1.dividersOf)(nb);
|
|
8
|
+
for (let i = 2; i < nb; i++) {
|
|
9
|
+
if (nb % i !== 0)
|
|
10
|
+
nonDividers.push(i);
|
|
11
|
+
}
|
|
12
|
+
return nonDividers;
|
|
13
|
+
};
|
|
14
|
+
exports.nonDivisorOf = nonDivisorOf;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.primeFactors = void 0;
|
|
4
|
-
/***
|
|
5
|
-
* returns array of prime factors
|
|
6
|
-
* e.g 12 -> [2, 2, 3]
|
|
7
|
-
*/
|
|
8
|
-
const primeFactors = (a) => {
|
|
9
|
-
const factors = [];
|
|
10
|
-
let divisor = 2;
|
|
11
|
-
while (a >= 2) {
|
|
12
|
-
if (a % divisor === 0) {
|
|
13
|
-
factors.push(divisor);
|
|
14
|
-
a = a / divisor;
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
divisor++;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return factors;
|
|
21
|
-
};
|
|
22
|
-
exports.primeFactors = primeFactors;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.primeFactors = void 0;
|
|
4
|
+
/***
|
|
5
|
+
* returns array of prime factors
|
|
6
|
+
* e.g 12 -> [2, 2, 3]
|
|
7
|
+
*/
|
|
8
|
+
const primeFactors = (a) => {
|
|
9
|
+
const factors = [];
|
|
10
|
+
let divisor = 2;
|
|
11
|
+
while (a >= 2) {
|
|
12
|
+
if (a % divisor === 0) {
|
|
13
|
+
factors.push(divisor);
|
|
14
|
+
a = a / divisor;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
divisor++;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return factors;
|
|
21
|
+
};
|
|
22
|
+
exports.primeFactors = primeFactors;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.decimalPartLengthOf = void 0;
|
|
4
|
-
const decimalPartLengthOf = (x) => {
|
|
5
|
-
function hasFraction(x) {
|
|
6
|
-
return Math.abs(Math.round(x) - x) > 1e-10;
|
|
7
|
-
}
|
|
8
|
-
let count = 0;
|
|
9
|
-
// multiply by increasing powers of 10 until the fractional part is ~ 0
|
|
10
|
-
while (hasFraction(x * 10 ** count) && isFinite(10 ** count))
|
|
11
|
-
count++;
|
|
12
|
-
return count;
|
|
13
|
-
};
|
|
14
|
-
exports.decimalPartLengthOf = decimalPartLengthOf;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decimalPartLengthOf = void 0;
|
|
4
|
+
const decimalPartLengthOf = (x) => {
|
|
5
|
+
function hasFraction(x) {
|
|
6
|
+
return Math.abs(Math.round(x) - x) > 1e-10;
|
|
7
|
+
}
|
|
8
|
+
let count = 0;
|
|
9
|
+
// multiply by increasing powers of 10 until the fractional part is ~ 0
|
|
10
|
+
while (hasFraction(x * 10 ** count) && isFinite(10 ** count))
|
|
11
|
+
count++;
|
|
12
|
+
return count;
|
|
13
|
+
};
|
|
14
|
+
exports.decimalPartLengthOf = decimalPartLengthOf;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.randint = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* @returns random [[a, b[[
|
|
6
|
-
*/
|
|
7
|
-
const randint = (a, b, excludes) => {
|
|
8
|
-
if (b === undefined)
|
|
9
|
-
return Math.floor(Math.random() * a);
|
|
10
|
-
if (!excludes)
|
|
11
|
-
return a + Math.floor(Math.random() * (b - a));
|
|
12
|
-
let res;
|
|
13
|
-
do {
|
|
14
|
-
res = a + Math.floor(Math.random() * (b - a));
|
|
15
|
-
} while (excludes.includes(res));
|
|
16
|
-
return res;
|
|
17
|
-
};
|
|
18
|
-
exports.randint = randint;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.randint = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @returns random [[a, b[[
|
|
6
|
+
*/
|
|
7
|
+
const randint = (a, b, excludes) => {
|
|
8
|
+
if (b === undefined)
|
|
9
|
+
return Math.floor(Math.random() * a);
|
|
10
|
+
if (!excludes)
|
|
11
|
+
return a + Math.floor(Math.random() * (b - a));
|
|
12
|
+
let res;
|
|
13
|
+
do {
|
|
14
|
+
res = a + Math.floor(Math.random() * (b - a));
|
|
15
|
+
} while (excludes.includes(res));
|
|
16
|
+
return res;
|
|
17
|
+
};
|
|
18
|
+
exports.randint = randint;
|
package/lib/mathutils/round.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.round = void 0;
|
|
4
|
-
const epsilon_1 = require("../numbers/epsilon");
|
|
5
|
-
function round(x, precision) {
|
|
6
|
-
return Math.round((x + epsilon_1.EPSILON) * Math.pow(10, precision)) / Math.pow(10, precision);
|
|
7
|
-
}
|
|
8
|
-
exports.round = round;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.round = void 0;
|
|
4
|
+
const epsilon_1 = require("../numbers/epsilon");
|
|
5
|
+
function round(x, precision) {
|
|
6
|
+
return Math.round((x + epsilon_1.EPSILON) * Math.pow(10, precision)) / Math.pow(10, precision);
|
|
7
|
+
}
|
|
8
|
+
exports.round = round;
|