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