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/6] 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 fabd4dc33dca83395d4c69cf9c02069554624e45 Mon Sep 17 00:00:00 2001 From: 0xNetcat Date: Thu, 15 Oct 2020 21:34:55 +0200 Subject: [PATCH 2/6] updated README.md --- README.md | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 94f68c3..541ea18 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,28 @@ # mathgenerator + A math problem generator, created for the purpose of giving self-studying students and teaching organizations the means to easily get access to random math problems to suit their needs. -To try out generators, go to https://todarith.ml/generate/ +To try out generators, go to If you have an idea for a generator, please add it as an issue and tag it with the "New Generator" label. ## Usage + The project can be install via pip -``` + +```bash pip install mathgenerator ``` + Here is an example of how you would generate an addition problem: -``` + +```python from mathgenerator import mathgen #generate an addition problem problem, solution = mathgen.addition() ``` + ## List of Generators | Id | Skill | Example problem | Example Solution | Function Name | @@ -35,3 +41,7 @@ problem, solution = mathgen.addition() | 11 | Basic Algebra | 9x + 7 = 10 | 1/3 | basicAlgebra | | 12 | Logarithm | log3(3) | 1 | log | | 13 | Easy Division | 270/15 = | 18 | intDivision | +| 14 | Decimal to Binary | Binary of a= | b | decimalToBinary | +| 15 | Binary to Decimal | Decimal of a= | b | binaryToDecimal | +| 16 | Fraction Division | (a/b)/(c/d)= | x/y | fractionDivision | +| 17 | Fraction Division | k * [[a,b],[c,d]]= | [[k*a,k*b],[k*c,k*d]] | intMatrix22Multiplication| From dc45a4be8d9dc4a26f98bf51a337d1d3016002a0 Mon Sep 17 00:00:00 2001 From: Akash verma <42277681+lusifer65@users.noreply.github.com> Date: Thu, 15 Oct 2020 15:40:50 -0400 Subject: [PATCH 3/6] Update mathgen.py midPointOfTwoPoint=Generator("Midpoint of the two point",18,"((X1,Y1),(X2,Y2))=","((X1+X2)/2,(Y1+Y2)/2)",MidPointOfTwoPoint) --- mathgenerator/mathgen.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index e9987ad..e17b369 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -215,6 +215,14 @@ def multiplyIntToMatrix22(maxMatrixVal = 10, maxRes = 100): problem = f"{constant} * [[{a}, {b}], [{c}, {d}]] = " solution = f"[[{a*constant},{b*constant}],[{c*constant},{d*constant}]]" return problem, solution +def MidPointOfTwoPoint(maxValue=20): + x1=random.randint(-20,maxValue) + y1=random.randint(-20,maxValue) + x2=random.randint(-20,maxValue) + y2=random.randint(-20,maxValue) + problem=f"({x1},{y1}),({x2},{y2})=" + solution=f"({(x1+x2)/2},{(y1+y2)/2})" + return problem,solution # || Class Instances @@ -238,4 +246,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) +midPointOfTwoPoint=Generator("Midpoint of the two point",18,"((X1,Y1),(X2,Y2))=","((X1+X2)/2,(Y1+Y2)/2)",MidPointOfTwoPoint) From 9397a919d3b4385e036f8fa049517a8cee598026 Mon Sep 17 00:00:00 2001 From: Luke Weiler Date: Thu, 15 Oct 2020 19:57:02 -0400 Subject: [PATCH 4/6] Update README.md --- README.md | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 541ea18..8ac09dd 100644 --- a/README.md +++ b/README.md @@ -25,23 +25,23 @@ problem, solution = mathgen.addition() ## List of Generators -| Id | Skill | Example problem | Example Solution | Function Name | -|------|-----------------------------------|--------------------|-------------------|--------------------------| -| 0 | Addition | 1+5= | 6 | addition | -| 1 | Subtraction | 9-4= | 5 | subtraction | -| 2 | Multiplication | 4*6= | 24 | multiplication | -| 3 | Division | 4/3= | 1.33333333 | division | -| 4 | Binary Complement 1s | 1010= | 0101 | binaryComplement1s | -| 5 | Modulo Division | 10%3= | 1 | moduloDivision | -| 6 | Square Root | sqrt(25)= | 5 | squareRootFunction | -| 7 | Power Rule Differentiation | 4x^3 | 12x^2 | powerRuleDifferentiation | -| 8 | Square | 4^2 | 16 | square | -| 9 | LCM (Least Common Multiple) | LCM of 14 and 9 = | 126 | lcm | -| 10 | GCD (Greatest Common Denominator) | GCD of 18 and 18 = | 18 | gcd | -| 11 | Basic Algebra | 9x + 7 = 10 | 1/3 | basicAlgebra | -| 12 | Logarithm | log3(3) | 1 | log | -| 13 | Easy Division | 270/15 = | 18 | intDivision | -| 14 | Decimal to Binary | Binary of a= | b | decimalToBinary | -| 15 | Binary to Decimal | Decimal of a= | b | binaryToDecimal | -| 16 | Fraction Division | (a/b)/(c/d)= | x/y | fractionDivision | -| 17 | Fraction Division | k * [[a,b],[c,d]]= | [[k*a,k*b],[k*c,k*d]] | intMatrix22Multiplication| +| Id | Skill | Example problem | Example Solution | Function Name | +|------|-----------------------------------|--------------------|-----------------------|--------------------------| +| 0 | Addition | 1+5= | 6 | addition | +| 1 | Subtraction | 9-4= | 5 | subtraction | +| 2 | Multiplication | 4*6= | 24 | multiplication | +| 3 | Division | 4/3= | 1.33333333 | division | +| 4 | Binary Complement 1s | 1010= | 0101 | binaryComplement1s | +| 5 | Modulo Division | 10%3= | 1 | moduloDivision | +| 6 | Square Root | sqrt(25)= | 5 | squareRootFunction | +| 7 | Power Rule Differentiation | 4x^3 | 12x^2 | powerRuleDifferentiation | +| 8 | Square | 4^2 | 16 | square | +| 9 | LCM (Least Common Multiple) | LCM of 14 and 9 = | 126 | lcm | +| 10 | GCD (Greatest Common Denominator) | GCD of 18 and 18 = | 18 | gcd | +| 11 | Basic Algebra | 9x + 7 = 10 | 1/3 | basicAlgebra | +| 12 | Logarithm | log3(3) | 1 | log | +| 13 | Easy Division | 270/15 = | 18 | intDivision | +| 14 | Decimal to Binary | Binary of a= | b | decimalToBinary | +| 15 | Binary to Decimal | Decimal of a= | b | binaryToDecimal | +| 16 | Fraction Division | (a/b)/(c/d)= | x/y | fractionDivision | +| 17 | Int 2x2 Matrix Multiplication | k * [[a,b],[c,d]]= | [[k*a,k*b],[k*c,k*d]] | intMatrix22Multiplication| From 3a19cdd8fde782d248cfad41996763a7235c9861 Mon Sep 17 00:00:00 2001 From: Luke Weiler Date: Thu, 15 Oct 2020 20:02:40 -0400 Subject: [PATCH 5/6] Fixed accidentally removed + sign --- mathgenerator/mathgen.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index bb99aae..f5a367d 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -222,7 +222,7 @@ def areaOfTriangleFunc(maxA=20, maxB=20, maxC=20): c = random.randint(1, maxC) s = (a+b+c)/2 area = (s*(s-a)*(s-b)*(s-c)) ** 0.5 - problem = "Area of triangle with side lengths: "+ str(a) +" "+ str(b) +" "+ str(c) " = " + problem = "Area of triangle with side lengths: "+ str(a) +" "+ str(b) +" "+ str(c) + " = " solution = area return problem, solution @@ -272,4 +272,4 @@ fractionDivision = Generator("Fraction Division", 16, "(a/b)/(c/d)=", "x/y", div intMatrix22Multiplication = Generator("Integer Multiplication with 2x2 Matrix", 17, "k * [[a,b],[c,d]]=", "[[k*a,k*b],[k*c,k*d]]", multiplyIntToMatrix22) areaOfTriangle = Generator("Area of Triangle", 18, "Area of Triangle with side lengths a, b, c = ", "area", areaOfTriangleFunc) doesTriangleExist = Generator("Triangle exists check", 19, "Does triangle with sides a, b and c exist?","Yes/No", isTriangleValidFunc) -midPointOfTwoPoint=Generator("Midpoint of the two point", 20,"((X1,Y1),(X2,Y2))=","((X1+X2)/2,(Y1+Y2)/2)",MidPointOfTwoPointFunc) \ No newline at end of file +midPointOfTwoPoint=Generator("Midpoint of the two point", 20,"((X1,Y1),(X2,Y2))=","((X1+X2)/2,(Y1+Y2)/2)",MidPointOfTwoPointFunc) From cc78098b4a983b19382d43baaf433e9f1b6d9427 Mon Sep 17 00:00:00 2001 From: Luke Weiler Date: Thu, 15 Oct 2020 21:35:07 -0400 Subject: [PATCH 6/6] 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})"