Added linearEquations generator

This commit is contained in:
Priyansh Anand
2020-10-16 15:57:23 +05:30
parent f905903bd4
commit 209bfb7978

View File

@@ -276,6 +276,29 @@ def factoringFunc(range_x1 = 10, range_x2 = 10):
solution = f"(x{x1})(x{x2})" solution = f"(x{x1})(x{x2})"
return problem, solution 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 # || Class Instances
#Format is: #Format is:
@@ -302,3 +325,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) 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) 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("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)