Merge branch 'master' into master

This commit is contained in:
Luke Weiler
2020-10-16 09:35:34 -04:00
committed by GitHub

View File

@@ -275,8 +275,61 @@ def factoringFunc(range_x1 = 10, range_x2 = 10):
x2 = intParser(x2) x2 = intParser(x2)
solution = f"(x{x1})(x{x2})" solution = f"(x{x1})(x{x2})"
return problem, solution return problem, solution
def thirdAngleOfTriangleFunc(maxAngle=89):
angle1 = random.randint(1, maxAngle)
angle2 = random.randint(1, maxAngle)
angle3 = 180 - (angle1 + angle2)
problem = f"Third angle of triangle with angles {angle1} and {angle2} = "
solution = angle3
return problem, solution
def distanceTwoPoints(maxValXY = 20, minValXY=-20): 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
def distanceTwoPointsFunc(maxValXY = 20, minValXY=-20):
point1X = random.randint(minValXY, maxValXY+1) point1X = random.randint(minValXY, maxValXY+1)
point1Y = random.randint(minValXY, maxValXY+1) point1Y = random.randint(minValXY, maxValXY+1)
point2X = random.randint(minValXY, maxValXY+1) point2X = random.randint(minValXY, maxValXY+1)
@@ -312,4 +365,7 @@ 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)
distance2Point = Generator("Distance between 2 points", 22, "Find the distance between (x1,y1) and (x2,y2)","sqrt(distanceSquared)", distanceTwoPoints) 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)