From 137cb81bef305533841ffdf55f3046741ffbdd3e Mon Sep 17 00:00:00 2001 From: Karol Dobiczek <32435586+drobiu@users.noreply.github.com> Date: Thu, 15 Oct 2020 20:40:11 +0200 Subject: [PATCH 1/2] Add factoring func --- mathgenerator/mathgen.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index e9987ad..3e2e5b6 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -216,6 +216,28 @@ def multiplyIntToMatrix22(maxMatrixVal = 10, maxRes = 100): solution = f"[[{a*constant},{b*constant}],[{c*constant},{d*constant}]]" return problem, solution +def factoringFunc(range_x1 = 10, range_x2 = 10): + x1 = random.randint(-range_x1, range_x1) + x2 = random.randint(-range_x2, range_x2) + def intParser(int): + if (int == 0): + return "" + if (int > 0): + return "+" + str(int) + if (int < 0): + return "-" + str(abs(int)) + + b = intParser(x1 + x2) + c = intParser(x1 * x2) + + if (b == ""): + b = "+" + + problem = f"x^2{b}x{c}" + x1 = intParser(x1) + x2 = intParser(x2) + solution = f"(x{x1})(x{x2})" + return problem, solution # || Class Instances @@ -238,4 +260,5 @@ intDivision = Generator("Easy Division", 13,"a/b=","c",divisionToIntFunc) decimalToBinary = Generator("Decimal to Binary",14,"Binary of a=","b",DecimalToBinaryFunc) binaryToDecimal = Generator("Binary to Decimal",15,"Decimal of a=","b",BinaryToDecimalFunc) fractionDivision = Generator("Fraction Division", 16, "(a/b)/(c/d)=", "x/y", divideFractionsFunc) -intMatrix22Multiplication = Generator("Integer Multiplication with 2x2 Matrix", 17, "k * [[a,b],[c,d]]=", "[[k*a,k*b],[k*c,k*d]]", multiplyIntToMatrix22) \ No newline at end of file +intMatrix22Multiplication = Generator("Integer Multiplication with 2x2 Matrix", 17, "k * [[a,b],[c,d]]=", "[[k*a,k*b],[k*c,k*d]]", multiplyIntToMatrix22) +factoring = Generator("Subtraction", 18, "x^2+(x1+x2)+x1*x2", "(x-x1)(x-x2", factoringFunc) From cc78098b4a983b19382d43baaf433e9f1b6d9427 Mon Sep 17 00:00:00 2001 From: Luke Weiler Date: Thu, 15 Oct 2020 21:35:07 -0400 Subject: [PATCH 2/2] Fixed error with second term of problem --- mathgenerator/mathgen.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 751c112..f13653d 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -254,10 +254,14 @@ def factoringFunc(range_x1 = 10, range_x2 = 10): b = intParser(x1 + x2) c = intParser(x1 * x2) + if (b == "+1"): + b = "+" + if (b == ""): - b = "+" + problem = f"x^2{c}" + else: + problem = f"x^2{b}x{c}" - problem = f"x^2{b}x{c}" x1 = intParser(x1) x2 = intParser(x2) solution = f"(x{x1})(x{x2})"