From d2830507cfdeb209aa1848f88b98c11a6e90c726 Mon Sep 17 00:00:00 2001 From: Aditya Mahimkar Date: Thu, 15 Oct 2020 23:38:32 +0530 Subject: [PATCH 01/19] Update mathgen.py --- mathgenerator/mathgen.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index a7063b2..54943b1 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -206,6 +206,16 @@ def divideFractionsFunc(maxVal=10): solution = x return problem, solution +def areaOfTriangleFunc(maxA=20, maxB=20, maxC=20): + a = random.randint(1, maxA) + b = random.randint(1, maxB) + 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) " = " + solution = area + return problem, solution + # || Class Instances #Format is: @@ -227,3 +237,4 @@ 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) +areaOfTriangle = Generator("Area of Triangle", 18, "Area of Triangle with side lengths a, b, c = ", "area", areaOfTriangleFunc) From 734dd662c5af557a86f9de4b2cfbdf375af8e2ee Mon Sep 17 00:00:00 2001 From: ieshaan12 Date: Thu, 15 Oct 2020 23:57:19 +0530 Subject: [PATCH 02/19] Triangle exists check --- mathgenerator/mathgen.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index e9987ad..c962df1 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -216,6 +216,19 @@ def multiplyIntToMatrix22(maxMatrixVal = 10, maxRes = 100): solution = f"[[{a*constant},{b*constant}],[{c*constant},{d*constant}]]" return problem, solution +def isTriangleValid(maxSideLength = 50): + sideA = random.randint(1, maxSideLength) + sideB = random.randint(1, maxSideLength) + sideC = random.randint(1, maxSideLength) + sideSums = [sideA + sideB, sideB + sideC, sideC + sideA] + sides = [sideC, sideA, sideB] + exists = True & (sides[0] < sideSums[0]) & (sides[1] < sideSums[1]) & (sides[2] < sideSums[2]) + problem = f"Does triangle with sides {sideA}, {sideB} and {sideC} exist?" + if exists: + solution = "Yes" + return problem, solution + solution = "No" + return problem, solution # || Class Instances @@ -238,4 +251,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) +doesTriangleExist = Generator("Triangle exists check", 18, "Does triangle with sides a, b and c exist?","Yes/No", isTriangleValid) 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 03/19] 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 04/19] 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 05/19] 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 06/19] 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 07/19] 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 08/19] 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})" From c767d09ac806521309088872c15f3134f1954161 Mon Sep 17 00:00:00 2001 From: ElRoberto13 Date: Thu, 15 Oct 2020 23:23:24 -0400 Subject: [PATCH 09/19] Simplify Radical, Issue #68 This adds the simplifyRadical generator, which simplifies a radical to its simplest form --- mathgenerator/mathgen.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 9918cd0..a23a761 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -276,6 +276,26 @@ def factoringFunc(range_x1 = 10, range_x2 = 10): solution = f"(x{x1})(x{x2})" return problem, solution +def simplifyRadicalFunc(range_x = 100): + x = random.randint(0, range_x) + if x == 1 or x == 0: + return f"sqrt({x})", str(x) + inside = x + outside = 1 + factor = 2 + while factor * factor <= inside: + if inside % (factor * factor) == 0: + # move factor^2 from inside to outside + inside //= (factor * factor) + outside *= factor + else: + factor += 1 + problem = f"sqrt({x})" + # exclude redundant multiplications by 1 + solution = str(outside if outside != 1 else '') + \ + (f"sqrt({inside})" if inside != 1 else "") + return problem, solution + # || Class Instances #Format is: @@ -301,4 +321,5 @@ intMatrix22Multiplication = Generator("Integer Multiplication with 2x2 Matrix", 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) -factoring = Generator("Subtraction", 21, "x^2+(x1+x2)+x1*x2", "(x-x1)(x-x2)", factoringFunc) \ No newline at end of file +factoring = Generator("Subtraction", 21, "x^2+(x1+x2)+x1*x2", "(x-x1)(x-x2)", factoringFunc) +simplifyRadical = Generator("Simplify a Radical", 22, "sqrt(72)", "6sqrt(2)", simplifyRadicalFunc) \ No newline at end of file From 4505fc897431c874c5dff1d0d6190d19b7d019b4 Mon Sep 17 00:00:00 2001 From: ElRoberto13 Date: Fri, 16 Oct 2020 01:27:03 -0400 Subject: [PATCH 10/19] Solves a system of equations Issue #67. Solves a system of equations of two variables (R^2) --- mathgenerator/mathgen.py | 49 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index a23a761..81e95ff 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -296,6 +296,51 @@ def simplifyRadicalFunc(range_x = 100): (f"sqrt({inside})" if inside != 1 else "") return problem, solution +def systemOfEquationsFunc(range_x = 10, range_y = 10, coeff_mult_range=10): + # Generate solution point first + x = random.randint(-range_x, range_x) + y = random.randint(-range_y, range_y) + # Start from reduced echelon form (coeffs 1) + c1 = [1, 0, x] + c2 = [0, 1, y] + + def randNonZero(): + return random.choice([i for i in range(-coeff_mult_range, coeff_mult_range) + if i != 0]) + # Add random (non-zero) multiple of equations (rows) to each other + c1_mult = randNonZero() + c2_mult = randNonZero() + new_c1 = [c1[i] + c1_mult * c2[i] for i in range(len(c1))] + new_c2 = [c2[i] + c2_mult * c1[i] for i in range(len(c2))] + + # For extra randomness, now add random (non-zero) multiples of original rows + # to themselves + c1_mult = randNonZero() + c2_mult = randNonZero() + new_c1 = [new_c1[i] + c1_mult * c1[i] for i in range(len(c1))] + new_c2 = [new_c2[i] + c2_mult * c2[i] for i in range(len(c2))] + + def coeffToFuncString(coeffs): + # lots of edge cases for perfect formatting! + x_sign = '-' if coeffs[0] < 0 else '' + # No redundant 1s + x_coeff = str(abs(coeffs[0])) if abs(coeffs[0]) != 1 else '' + # If x coeff is 0, dont include x + x_str = f'{x_sign}{x_coeff}x' if coeffs[0] != 0 else '' + # if x isn't included and y is positive, dont include operator + op = ' - ' if coeffs[1] < 0 else (' + ' if x_str != '' else '') + # No redundant 1s + y_coeff = abs(coeffs[1]) if abs(coeffs[1]) != 1 else '' + # Don't include if 0, unless x is also 0 (probably never happens) + y_str = f'{y_coeff}y' if coeffs[1] != 0 else ('' if x_str != '' else '0') + return f'{x_str}{op}{y_str} = {coeffs[2]}' + + problem = f"{coeffToFuncString(new_c1)}, {coeffToFuncString(new_c2)}" + solution = f"x = {x}, y = {y}" + return problem, solution + + # Add random (non-zero) multiple of equations to each other + # || Class Instances #Format is: @@ -322,4 +367,6 @@ areaOfTriangle = Generator("Area of Triangle", 18, "Area of Triangle with side l 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) factoring = Generator("Subtraction", 21, "x^2+(x1+x2)+x1*x2", "(x-x1)(x-x2)", factoringFunc) -simplifyRadical = Generator("Simplify a Radical", 22, "sqrt(72)", "6sqrt(2)", simplifyRadicalFunc) \ No newline at end of file +simplifyRadical = Generator("Simplify a Radical", 22, "sqrt(72)", "6sqrt(2)", simplifyRadicalFunc) +systemOfEquations = Generator("Solve a System of Equations in R^2", 23, "2x + 5y = 13, -3x - 3y = -6", "x = -1, y = 3", + systemOfEquationsFunc) \ No newline at end of file From 642574148653ff1d743b339791e6281ce3092e55 Mon Sep 17 00:00:00 2001 From: ElRoberto13 Date: Fri, 16 Oct 2020 01:32:46 -0400 Subject: [PATCH 11/19] Remove radical function from branch --- mathgenerator/mathgen.py | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 81e95ff..e7ca613 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -276,26 +276,6 @@ def factoringFunc(range_x1 = 10, range_x2 = 10): solution = f"(x{x1})(x{x2})" return problem, solution -def simplifyRadicalFunc(range_x = 100): - x = random.randint(0, range_x) - if x == 1 or x == 0: - return f"sqrt({x})", str(x) - inside = x - outside = 1 - factor = 2 - while factor * factor <= inside: - if inside % (factor * factor) == 0: - # move factor^2 from inside to outside - inside //= (factor * factor) - outside *= factor - else: - factor += 1 - problem = f"sqrt({x})" - # exclude redundant multiplications by 1 - solution = str(outside if outside != 1 else '') + \ - (f"sqrt({inside})" if inside != 1 else "") - return problem, solution - def systemOfEquationsFunc(range_x = 10, range_y = 10, coeff_mult_range=10): # Generate solution point first x = random.randint(-range_x, range_x) @@ -367,6 +347,5 @@ areaOfTriangle = Generator("Area of Triangle", 18, "Area of Triangle with side l 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) factoring = Generator("Subtraction", 21, "x^2+(x1+x2)+x1*x2", "(x-x1)(x-x2)", factoringFunc) -simplifyRadical = Generator("Simplify a Radical", 22, "sqrt(72)", "6sqrt(2)", simplifyRadicalFunc) systemOfEquations = Generator("Solve a System of Equations in R^2", 23, "2x + 5y = 13, -3x - 3y = -6", "x = -1, y = 3", systemOfEquationsFunc) \ No newline at end of file From 6ccb1a9bc7fa3bad872947be65f853136ba84928 Mon Sep 17 00:00:00 2001 From: Aditya Mahimkar Date: Fri, 16 Oct 2020 11:11:42 +0530 Subject: [PATCH 12/19] Update mathgen.py --- mathgenerator/mathgen.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 9918cd0..7a7205e 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -276,6 +276,13 @@ def factoringFunc(range_x1 = 10, range_x2 = 10): solution = f"(x{x1})(x{x2})" return problem, solution +def thirdAngleOfTriangle(maxAngle=180): + angle1 = random.randint(1, maxAngle) + x1 = random.randint(1, maxAngle) + angle3 = 180 - (angle1 + angle2) + problem = "Third angle = " + + # || Class Instances #Format is: @@ -301,4 +308,4 @@ intMatrix22Multiplication = Generator("Integer Multiplication with 2x2 Matrix", 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) -factoring = Generator("Subtraction", 21, "x^2+(x1+x2)+x1*x2", "(x-x1)(x-x2)", factoringFunc) \ No newline at end of file +factoring = Generator("Subtraction", 21, "x^2+(x1+x2)+x1*x2", "(x-x1)(x-x2)", factoringFunc) From f73df71c23adc3de39674b04b79e614dad42bde1 Mon Sep 17 00:00:00 2001 From: Aditya Mahimkar Date: Fri, 16 Oct 2020 11:56:03 +0530 Subject: [PATCH 13/19] Update mathgen.py --- mathgenerator/mathgen.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 7a7205e..e74000a 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -276,12 +276,13 @@ def factoringFunc(range_x1 = 10, range_x2 = 10): solution = f"(x{x1})(x{x2})" return problem, solution -def thirdAngleOfTriangle(maxAngle=180): +def thirdAngleOfTriangleFunc(maxAngle=180): angle1 = random.randint(1, maxAngle) x1 = random.randint(1, maxAngle) angle3 = 180 - (angle1 + angle2) problem = "Third angle = " - + solution = angle3 + return problem, solution # || Class Instances @@ -309,3 +310,4 @@ areaOfTriangle = Generator("Area of Triangle", 18, "Area of Triangle with side l 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) factoring = Generator("Subtraction", 21, "x^2+(x1+x2)+x1*x2", "(x-x1)(x-x2)", factoringFunc) +thirdAngleOfTriangle = Generator("Third Angle of Triangle", 22, "Third Angle of the triangle = ", "angle3", thirdAngleOfTriangleFunc) From 6248336226d4297aa68452a3f154d3ff958c39f5 Mon Sep 17 00:00:00 2001 From: Aditya Mahimkar Date: Fri, 16 Oct 2020 12:06:50 +0530 Subject: [PATCH 14/19] Update mathgen.py --- mathgenerator/mathgen.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index e74000a..226d8a9 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -276,11 +276,11 @@ def factoringFunc(range_x1 = 10, range_x2 = 10): solution = f"(x{x1})(x{x2})" return problem, solution -def thirdAngleOfTriangleFunc(maxAngle=180): +def thirdAngleOfTriangleFunc(maxAngle=89): angle1 = random.randint(1, maxAngle) - x1 = random.randint(1, maxAngle) + angle2 = random.randint(1, maxAngle) angle3 = 180 - (angle1 + angle2) - problem = "Third angle = " + problem = "Third angle of triangle = " solution = angle3 return problem, solution From 1bedf32949e0e378533b12dc30ea3d47b4fef4fd Mon Sep 17 00:00:00 2001 From: ieshaan12 Date: Fri, 16 Oct 2020 12:24:30 +0530 Subject: [PATCH 15/19] Two Point distance --- mathgenerator/mathgen.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 9918cd0..e6b529a 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -276,6 +276,16 @@ def factoringFunc(range_x1 = 10, range_x2 = 10): solution = f"(x{x1})(x{x2})" return problem, solution +def distanceTwoPoints(maxValXY = 20, minValXY=-20): + point1X = random.randint(minValXY, maxValXY+1) + point1Y = random.randint(minValXY, maxValXY+1) + point2X = random.randint(minValXY, maxValXY+1) + point2Y = random.randint(minValXY, maxValXY+1) + distanceSq = (point1X - point2X) ** 2 + (point1Y - point2Y) ** 2 + solution = f"sqrt({distanceSq})" + problem = f"Find the distance between ({point1X}, {point1Y}) and ({point2X}, {point2Y})" + return problem, solution + # || Class Instances #Format is: @@ -301,4 +311,5 @@ intMatrix22Multiplication = Generator("Integer Multiplication with 2x2 Matrix", 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) -factoring = Generator("Subtraction", 21, "x^2+(x1+x2)+x1*x2", "(x-x1)(x-x2)", factoringFunc) \ No newline at end of file +factoring = Generator("Subtraction", 21, "x^2+(x1+x2)+x1*x2", "(x-x1)(x-x2)", factoringFunc) +distance2Point = Generator("Distance between 2 points", 22, "Find the distance between (x1,y1) and (x2,y2)","sqrt(distanceSquared)", distanceTwoPoints) \ No newline at end of file From f905903bd4d7d8bc32d64a8e50af70ed7fab780b Mon Sep 17 00:00:00 2001 From: Priyansh Anand Date: Fri, 16 Oct 2020 15:55:27 +0530 Subject: [PATCH 16/19] Allowed to pass arguments to the generator functions (optional) --- mathgenerator/mathgen.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 9918cd0..88b05b9 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -15,8 +15,8 @@ class Generator: def __str__(self): return str(self.id) + " " + self.title + " " + self.generalProb + " " + self.generalSol - def __call__(self): - return self.func() + def __call__(self, **kwargs): + return self.func(**kwargs) # || Non-generator Functions def genById(id): From 209bfb7978ed37718a09d6f9c77e45f3a11d1a7d Mon Sep 17 00:00:00 2001 From: Priyansh Anand Date: Fri, 16 Oct 2020 15:57:23 +0530 Subject: [PATCH 17/19] Added linearEquations generator --- mathgenerator/mathgen.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 88b05b9..247fab8 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -276,6 +276,29 @@ def factoringFunc(range_x1 = 10, range_x2 = 10): solution = f"(x{x1})(x{x2})" return problem, solution +def linearEquationsFunc(n = 2, varRange = 20, coeffRange = 20): + if n > 10: + print("[!] n cannot be greater than 10") + return None, None + + vars = ['x', 'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g'][:n] + soln = [ random.randint(-varRange, varRange) for i in range(n) ] + + problem = list() + solution = ", ".join(["{} = {}".format(vars[i], soln[i]) for i in range(n)]) + for _ in range(n): + coeff = [ random.randint(-coeffRange, coeffRange) for i in range(n) ] + res = sum([ coeff[i] * soln[i] for i in range(n)]) + + prob = ["{}{}".format(coeff[i], vars[i]) if coeff[i] != 0 else "" for i in range(n)] + while "" in prob: + prob.remove("") + prob = " + ".join(prob) + " = " + str(res) + problem.append(prob) + + problem = "\n".join(problem) + return problem, solution + # || Class Instances #Format is: @@ -301,4 +324,5 @@ intMatrix22Multiplication = Generator("Integer Multiplication with 2x2 Matrix", 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) -factoring = Generator("Subtraction", 21, "x^2+(x1+x2)+x1*x2", "(x-x1)(x-x2)", factoringFunc) \ No newline at end of file +factoring = Generator("Subtraction", 21, "x^2+(x1+x2)+x1*x2", "(x-x1)(x-x2)", factoringFunc) +linearEquations = Generator("Linear Equations", 22, "2x+5y=20 & 3x+6y=12", "x=-20 & y=12", linearEquationsFunc) \ No newline at end of file From 887cedda9f7d5cf8ce8292bdc44e5f2972165993 Mon Sep 17 00:00:00 2001 From: Ananya Kaushik Date: Fri, 16 Oct 2020 05:46:44 -0700 Subject: [PATCH 18/19] add Pythagorean theorem --- mathgenerator/mathgen.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 9918cd0..df35240 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -276,6 +276,14 @@ def factoringFunc(range_x1 = 10, range_x2 = 10): solution = f"(x{x1})(x{x2})" return problem, solution +def pythagoreanTheoremFunc(maxLength = 20): + a = random.randint(1, maxLength) + b = random.randint(1, maxLength) + c = (a**2 + b**2)**0.5 + problem = f"The hypotenuse of a right triangle given the other two lengths {a} and {b} = " + solution = f"{c:.0f}" if c.is_integer() else f"{c:.2f}" + return problem, solution + # || Class Instances #Format is: @@ -301,4 +309,5 @@ intMatrix22Multiplication = Generator("Integer Multiplication with 2x2 Matrix", 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) -factoring = Generator("Subtraction", 21, "x^2+(x1+x2)+x1*x2", "(x-x1)(x-x2)", factoringFunc) \ No newline at end of file +factoring = Generator("Subtraction", 21, "x^2+(x1+x2)+x1*x2", "(x-x1)(x-x2)", factoringFunc) +pythagoreanTheorem = Generator("Pythagorean Theorem", 22, "The hypotenuse of a right triangle given the other two lengths a and b = ", "hypotenuse", pythagoreanTheoremFunc) \ No newline at end of file From bfb7e1ba7ac742abe2368cb87eb11e99d8865d8c Mon Sep 17 00:00:00 2001 From: Luke Weiler Date: Fri, 16 Oct 2020 10:17:36 -0400 Subject: [PATCH 19/19] Fixed factoring name and added comment to 26 --- mathgenerator/mathgen.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index d19199f..31047ef 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -395,10 +395,10 @@ intMatrix22Multiplication = Generator("Integer Multiplication with 2x2 Matrix", 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) -factoring = Generator("Subtraction", 21, "x^2+(x1+x2)+x1*x2", "(x-x1)(x-x2)", factoringFunc) +factoring = Generator("Factoring Quadratic", 21, "x^2+(x1+x2)+x1*x2", "(x-x1)(x-x2)", factoringFunc) thirdAngleOfTriangle = Generator("Third Angle of Triangle", 22, "Third Angle of the triangle = ", "angle3", thirdAngleOfTriangleFunc) systemOfEquations = Generator("Solve a System of Equations in R^2", 23, "2x + 5y = 13, -3x - 3y = -6", "x = -1, y = 3", systemOfEquationsFunc) distance2Point = Generator("Distance between 2 points", 24, "Find the distance between (x1,y1) and (x2,y2)","sqrt(distanceSquared)", distanceTwoPointsFunc) pythagoreanTheorem = Generator("Pythagorean Theorem", 25, "The hypotenuse of a right triangle given the other two lengths a and b = ", "hypotenuse", pythagoreanTheoremFunc) -linearEquations = Generator("Linear Equations", 26, "2x+5y=20 & 3x+6y=12", "x=-20 & y=12", linearEquationsFunc) +linearEquations = Generator("Linear Equations", 26, "2x+5y=20 & 3x+6y=12", "x=-20 & y=12", linearEquationsFunc) #This has multiple variables whereas #23 has only x and y