math-exercises 3.0.80 → 3.0.82
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/exercises/math/calcul/arithmetics/isNumberDecimal.d.ts.map +1 -1
- package/lib/exercises/math/calcul/arithmetics/isNumberDecimal.js +16 -9
- package/lib/math/numbers/rationals/rational.d.ts +1 -0
- package/lib/math/numbers/rationals/rational.d.ts.map +1 -1
- package/lib/math/numbers/rationals/rational.js +4 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isNumberDecimal.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calcul/arithmetics/isNumberDecimal.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAeT,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"isNumberDecimal.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calcul/arithmetics/isNumberDecimal.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAeT,MAAM,6BAA6B,CAAC;AAOrC,OAAO,EACL,eAAe,EAEhB,MAAM,qCAAqC,CAAC;AAY7C,KAAK,WAAW,GAAG;IACjB,OAAO,EAAE;QACP,CAAC,EAAE,eAAe,CAAC;QACnB,SAAS,EAAE,OAAO,CAAC;KACpB,EAAE,CAAC;CACL,CAAC;AAmIF,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,WAAW,CAmBjD,CAAC"}
|
|
@@ -4,10 +4,11 @@ import { RationalConstructor } from "../../../../math/numbers/rationals/rational
|
|
|
4
4
|
import { randfloat } from "../../../../math/utils/random/randfloat.js";
|
|
5
5
|
import { randint } from "../../../../math/utils/random/randint.js";
|
|
6
6
|
import { reifyAlgebraic, } from "../../../../tree/nodes/nodeConstructor.js";
|
|
7
|
-
import {
|
|
7
|
+
import { PiNode } from "../../../../tree/nodes/numbers/piNode.js";
|
|
8
8
|
import { isFractionNode, } from "../../../../tree/nodes/operators/fractionNode.js";
|
|
9
9
|
import { coinFlip } from "../../../../utils/alea/coinFlip.js";
|
|
10
10
|
import { random } from "../../../../utils/alea/random.js";
|
|
11
|
+
import { doWhile } from "../../../../utils/doWhile.js";
|
|
11
12
|
import { handleVEAError } from "../../../../utils/errors/handleVEAError.js";
|
|
12
13
|
const getPropositions = (n, { answer, options }) => {
|
|
13
14
|
const propositions = [];
|
|
@@ -75,14 +76,15 @@ const isAnswerValid = (ans, { answer }) => {
|
|
|
75
76
|
};
|
|
76
77
|
const generateNonDecimalNumber = () => {
|
|
77
78
|
const nonDecimals = [];
|
|
78
|
-
nonDecimals.push(
|
|
79
|
-
nonDecimals.push(
|
|
79
|
+
nonDecimals.push(RationalConstructor.randomPureRational().toTree());
|
|
80
|
+
nonDecimals.push(PiNode);
|
|
80
81
|
return random(nonDecimals);
|
|
81
82
|
};
|
|
82
83
|
const generateDecimalNumber = () => {
|
|
83
84
|
const decimals = [];
|
|
84
|
-
decimals.push(
|
|
85
|
-
decimals.push(
|
|
85
|
+
decimals.push(randint(0, 100).toTree());
|
|
86
|
+
decimals.push(randfloat(0, 100, 2).toTree());
|
|
87
|
+
decimals.push(RationalConstructor.randomDecimal().toTree());
|
|
86
88
|
return random(decimals);
|
|
87
89
|
};
|
|
88
90
|
const getIsNumberdecimalQuestion = (ops) => {
|
|
@@ -93,12 +95,17 @@ const getIsNumberdecimalQuestion = (ops) => {
|
|
|
93
95
|
choices.push({ a: nonDecimal, isDecimal: false });
|
|
94
96
|
for (let i = 0; i < 2; i++) {
|
|
95
97
|
const isDecimal = coinFlip();
|
|
96
|
-
const randomNumber = isDecimal
|
|
97
|
-
? generateDecimalNumber()
|
|
98
|
-
: generateNonDecimalNumber();
|
|
98
|
+
const randomNumber = doWhile(() => (isDecimal ? generateDecimalNumber() : generateNonDecimalNumber()), (a) => choices.some((c) => c.a.toTex() === a.toTex()));
|
|
99
99
|
choices.push({ a: randomNumber, isDecimal });
|
|
100
100
|
}
|
|
101
|
-
const identifiers = {
|
|
101
|
+
const identifiers = {
|
|
102
|
+
options: choices.map((c) => {
|
|
103
|
+
return {
|
|
104
|
+
a: c.a.toIdentifiers(),
|
|
105
|
+
isDecimal: c.isDecimal,
|
|
106
|
+
};
|
|
107
|
+
}),
|
|
108
|
+
};
|
|
102
109
|
return getQuestionFromIdentifiers(identifiers);
|
|
103
110
|
};
|
|
104
111
|
const getQuestionFromIdentifiers = (identifiers) => {
|
|
@@ -13,6 +13,7 @@ export declare abstract class RationalConstructor {
|
|
|
13
13
|
static randomIrreductibleProba(maxDenum?: number): Rational | Integer;
|
|
14
14
|
static randomIrreductibleWithSign(max?: number): Rational;
|
|
15
15
|
static randomPureRational(max?: number): Rational;
|
|
16
|
+
static randomDecimal(max?: number): Rational;
|
|
16
17
|
}
|
|
17
18
|
export declare class Rational implements Nombre {
|
|
18
19
|
num: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rational.d.ts","sourceRoot":"","sources":["../../../../src/math/numbers/rationals/rational.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAElE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAQvD,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAElD,8BAAsB,mBAAmB;IACvC;;OAEG;IACH,MAAM,CAAC,kBAAkB,CAAC,MAAM,GAAE,MAAW;IAW7C,MAAM,CAAC,kBAAkB,CACvB,GAAG,GAAE,MAAW,EAChB,EAAE,UAAkB,EAAE,GAAE;QAAE,UAAU,CAAC,EAAE,OAAO,CAAA;KAAO;IASvD,MAAM,CAAC,uBAAuB,CAAC,QAAQ,GAAE,MAAW;IAKpD,MAAM,CAAC,0BAA0B,CAAC,GAAG,GAAE,MAAW;IAQlD,MAAM,CAAC,kBAAkB,CAAC,GAAG,GAAE,MAAW;
|
|
1
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,MAAM,GAAG,MAAM;IAgB1B,QAAQ,IAAI,QAAQ;IAIpB,MAAM,CAAC,IAAI,CAAC,EAAE,WAAW,GAAG,aAAa;IAgBzC,cAAc;IAId,QAAQ,IAAI,OAAO,GAAG,QAAQ;CAqB/B"}
|
|
@@ -56,6 +56,10 @@ export class RationalConstructor {
|
|
|
56
56
|
const frac = doWhile(() => RationalConstructor.randomIrreductible(max), (x) => round(x.value, 10) === x.value);
|
|
57
57
|
return frac;
|
|
58
58
|
}
|
|
59
|
+
static randomDecimal(max = 20) {
|
|
60
|
+
const frac = doWhile(() => RationalConstructor.randomIrreductible(max), (x) => round(x.value, 5) !== x.value);
|
|
61
|
+
return frac;
|
|
62
|
+
}
|
|
59
63
|
}
|
|
60
64
|
export class Rational {
|
|
61
65
|
num;
|