Merge branch 'master' into master

This commit is contained in:
Luke Weiler
2020-10-17 14:04:39 -04:00
committed by GitHub
2 changed files with 45 additions and 21 deletions

25
makeReadme.py Normal file
View File

@@ -0,0 +1,25 @@
#To use, paste at bottom of mathgen.py code, change line variable and remove all table rows in README.md except for the top 2 and run mathgen.py
wList = getGenList()
allRows = []
f=open('mathgen.py')
lines=f.readlines()
line = 720 #This has to be changed depending on which line the first generator appears on
for item in wList:
myGen = item[2]
prob, sol = myGen()
prob = str(prob).rstrip("\n")
sol = str(sol).rstrip("\n")
instName = lines[line]
def_name = instName[:instName.find('=')].strip()
row = [myGen.id, myGen.title, prob, sol, def_name]
line+=1
allRows.append(row)
g=open('../README.md', "a")
for row in allRows:
tableLine = "| " + str(row[0]) + " | " + str(row[1]) + " | " + str(row[2]) + " | " + str(row[3]) + " | " + str(row[4]) + " |\n"
g.write(tableLine)
g.close()
print("New README.md table generated")

View File

@@ -224,7 +224,7 @@ def areaOfTriangleFunc(maxA=20, maxB=20, maxC=20):
c = random.randint(1, maxC) c = random.randint(1, maxC)
s = (a+b+c)/2 s = (a+b+c)/2
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5 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 solution = area
return problem, solution return problem, solution
@@ -234,7 +234,7 @@ def isTriangleValidFunc(maxSideLength = 50):
sideC = random.randint(1, maxSideLength) sideC = random.randint(1, maxSideLength)
sideSums = [sideA + sideB, sideB + sideC, sideC + sideA] sideSums = [sideA + sideB, sideB + sideC, sideC + sideA]
sides = [sideC, sideA, sideB] sides = [sideC, sideA, sideB]
exists = True & (sides[0] < sideSums[0]) & (sides[1] < sideSums[1]) & (sides[2] < sideSums[2]) 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?" problem = f"Does triangle with sides {sideA}, {sideB} and {sideC} exist?"
if exists: if exists:
solution = "Yes" solution = "Yes"
@@ -267,7 +267,7 @@ def factoringFunc(range_x1 = 10, range_x2 = 10):
if (b == "+1"): if (b == "+1"):
b = "+" b = "+"
if (b == ""): if (b == ""):
problem = f"x^2{c}" problem = f"x^2{c}"
else: else:
@@ -277,7 +277,7 @@ 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): def thirdAngleOfTriangleFunc(maxAngle=89):
angle1 = random.randint(1, maxAngle) angle1 = random.randint(1, maxAngle)
angle2 = random.randint(1, maxAngle) angle2 = random.randint(1, maxAngle)
@@ -362,13 +362,13 @@ def linearEquationsFunc(n = 2, varRange = 20, coeffRange = 20):
for _ in range(n): for _ in range(n):
coeff = [ random.randint(-coeffRange, coeffRange) for i in range(n) ] coeff = [ random.randint(-coeffRange, coeffRange) for i in range(n) ]
res = sum([ coeff[i] * soln[i] 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)] prob = ["{}{}".format(coeff[i], vars[i]) if coeff[i] != 0 else "" for i in range(n)]
while "" in prob: while "" in prob:
prob.remove("") prob.remove("")
prob = " + ".join(prob) + " = " + str(res) prob = " + ".join(prob) + " = " + str(res)
problem.append(prob) problem.append(prob)
problem = "\n".join(problem) problem = "\n".join(problem)
return problem, solution return problem, solution
@@ -417,8 +417,8 @@ def regularPolygonAngleFunc(minVal = 3,maxVal = 20):
problem = f"Find the angle of a regular polygon with {sideNum} sides" problem = f"Find the angle of a regular polygon with {sideNum} sides"
exteriorAngle = round((360/sideNum),2) exteriorAngle = round((360/sideNum),2)
solution = 180 - exteriorAngle solution = 180 - exteriorAngle
return problem, solution return problem, solution
def combinationsFunc(maxlength=20): def combinationsFunc(maxlength=20):
def factorial(a): def factorial(a):
@@ -434,9 +434,9 @@ def combinationsFunc(maxlength=20):
solution= int(factorial(a)/(factorial(b)*factorial(a-b))) solution= int(factorial(a)/(factorial(b)*factorial(a-b)))
problem= "Number of combinations from {} objects picked {} at a time ".format(a,b) problem= "Number of combinations from {} objects picked {} at a time ".format(a,b)
return problem, solution return problem, solution
def factorialFunc(maxInput = 6): def factorialFunc(maxInput = 6):
a = random.randint(0, maxInput) a = random.randint(0, maxInput)
n = a n = a
@@ -470,7 +470,7 @@ def surfaceAreaCuboid(maxSide = 20, unit = 'm'):
a = random.randint(1, maxSide) a = random.randint(1, maxSide)
b = random.randint(1, maxSide) b = random.randint(1, maxSide)
c = random.randint(1, maxSide) c = random.randint(1, maxSide)
problem = f"Surface area of cuboid with sides = {a}{unit}, {b}{unit}, {c}{unit} is" problem = f"Surface area of cuboid with sides = {a}{unit}, {b}{unit}, {c}{unit} is"
ans = 2 * (a*b + b*c + c*a) ans = 2 * (a*b + b*c + c*a)
solution = f"{ans} {unit}^2" solution = f"{ans} {unit}^2"
@@ -567,7 +567,7 @@ def intersectionOfTwoLinesFunc(
else: else:
x = f"{x.numerator}/{x.denominator}" x = f"{x.numerator}/{x.denominator}"
return x return x
m1 = (random.randint(minM, maxM), random.randint(minDenominator, maxDenominator)) m1 = (random.randint(minM, maxM), random.randint(minDenominator, maxDenominator))
m2 = (random.randint(minM, maxM), random.randint(minDenominator, maxDenominator)) m2 = (random.randint(minM, maxM), random.randint(minDenominator, maxDenominator))
b1 = random.randint(minB, maxB) b1 = random.randint(minB, maxB)
@@ -625,7 +625,7 @@ def compareFractionsFunc(maxVal=10):
solution="<" solution="<"
else: else:
solution="=" solution="="
problem = f"Which symbol represents the comparison between {a}/{b} and {c}/{d}?" problem = f"Which symbol represents the comparison between {a}/{b} and {c}/{d}?"
return problem,solution return problem,solution
@@ -648,7 +648,7 @@ def matrixMultiplicationFunc(maxVal=100):
a.append([]) a.append([])
for c in range(n): for c in range(n):
a[r].append(random.randint(-maxVal,maxVal)) a[r].append(random.randint(-maxVal,maxVal))
b=[] b=[]
for r in range(n): for r in range(n):
b.append([]) b.append([])
@@ -666,8 +666,8 @@ def matrixMultiplicationFunc(maxVal=100):
for t in range(n): for t in range(n):
temp+=a[r][t]*b[t][c] temp+=a[r][t]*b[t][c]
res[r].append(temp) res[r].append(temp)
problem= f"Multiply \n{a_string}\n and \n\n{b_string}" #consider using a, b instead of a_string, b_string if the problem doesn't look right problem= f"Multiply {a} and {b}" #consider using a, b instead of a_string, b_string if the problem doesn't look right
solution= matrixMultiplicationFuncHelper(res) solution= res#matrixMultiplicationFuncHelper(res)
return problem, solution return problem, solution
def matrixMultiplicationFuncHelper(inp): def matrixMultiplicationFuncHelper(inp):
@@ -703,7 +703,7 @@ def powerRuleIntegrationFunc(maxCoef = 10, maxExp = 10, maxTerms = 5):
solution = solution + " + c" solution = solution + " + c"
return problem, solution return problem, solution
def fourthAngleOfQuadriFunc(maxAngle = 180): def fourthAngleOfQuadriFunc(maxAngle = 180):
angle1 = random.randint(1, maxAngle) angle1 = random.randint(1, maxAngle)
angle2 = random.randint(1, 240-angle1) angle2 = random.randint(1, 240-angle1)
@@ -860,8 +860,7 @@ doesTriangleExist = Generator("Triangle exists check", 19, "Does triangle with s
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("Factoring Quadratic", 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) 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", systemOfEquations = Generator("Solve a System of Equations in R^2", 23, "2x + 5y = 13, -3x - 3y = -6", "x = -1, y = 3", systemOfEquationsFunc)
systemOfEquationsFunc)
distance2Point = Generator("Distance between 2 points", 24, "Find the distance between (x1,y1) and (x2,y2)","sqrt(distanceSquared)", distanceTwoPointsFunc) 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) 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) #This has multiple variables whereas #23 has only x and y 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
@@ -873,7 +872,7 @@ factorial = Generator("Factorial", 31, "a! = ", "b", factorialFunc)
surfaceAreaCubeGen = Generator("Surface Area of Cube", 32, "Surface area of cube with side a units is","b units^2", surfaceAreaCube) surfaceAreaCubeGen = Generator("Surface Area of Cube", 32, "Surface area of cube with side a units is","b units^2", surfaceAreaCube)
surfaceAreaCuboidGen = Generator("Surface Area of Cuboid", 33, "Surface area of cuboid with sides = a units, b units, c units is","d units^2", surfaceAreaCuboid) surfaceAreaCuboidGen = Generator("Surface Area of Cuboid", 33, "Surface area of cuboid with sides = a units, b units, c units is","d units^2", surfaceAreaCuboid)
surfaceAreaCylinderGen = Generator("Surface Area of Cylinder", 34, "Surface area of cylinder with height = a units and radius = b units is","c units^2", surfaceAreaCylinder) surfaceAreaCylinderGen = Generator("Surface Area of Cylinder", 34, "Surface area of cylinder with height = a units and radius = b units is","c units^2", surfaceAreaCylinder)
volumeCubeGen = Generator("Volum of Cube", 35, "Volume of cube with side a units is","b units^3", volumeCube) volumeCubeGen = Generator("Volum of Cube", 35, "Volume of cube with side a units is","b units^3", volumeCube)
volumeCuboidGen = Generator("Volume of Cuboid", 36, "Volume of cuboid with sides = a units, b units, c units is","d units^3", volumeCuboid) volumeCuboidGen = Generator("Volume of Cuboid", 36, "Volume of cuboid with sides = a units, b units, c units is","d units^3", volumeCuboid)
volumeCylinderGen = Generator("Volume of cylinder", 37, "Volume of cylinder with height = a units and radius = b units is","c units^3", volumeCylinder) volumeCylinderGen = Generator("Volume of cylinder", 37, "Volume of cylinder with height = a units and radius = b units is","c units^3", volumeCylinder)
surfaceAreaConeGen = Generator("Surface Area of cone", 38, "Surface area of cone with height = a units and radius = b units is","c units^2", surfaceAreaCone) surfaceAreaConeGen = Generator("Surface Area of cone", 38, "Surface area of cone with height = a units and radius = b units is","c units^2", surfaceAreaCone)
@@ -896,4 +895,4 @@ confidenceInterval = Generator("Confidence interval For sample S", 54, "With X%
surdsComparison = Generator("Comparing surds", 55, "Fill in the blanks a^(1/b) _ c^(1/d)", "</>/=", surdsComparisonFunc) surdsComparison = Generator("Comparing surds", 55, "Fill in the blanks a^(1/b) _ c^(1/d)", "</>/=", surdsComparisonFunc)
fibonacciSeries = Generator("Fibonacci Series",56,"fibonacci series of first a numbers","prints the fibonacci series starting from 0 to a",fibonacciSeriesFunc) fibonacciSeries = Generator("Fibonacci Series",56,"fibonacci series of first a numbers","prints the fibonacci series starting from 0 to a",fibonacciSeriesFunc)
basicTrigonometry=Generator("Trigonometric Values",57,"What is sin(X)?","ans",basicTrigonometryFunc) basicTrigonometry=Generator("Trigonometric Values",57,"What is sin(X)?","ans",basicTrigonometryFunc)
sumOfAnglesOfPolygon = Generator("Sum of Angles of Polygon", 58, "Sum of angles of polygon with n sides = ", "sum", sumOfAnglesOfPolygonFunc) sumOfAnglesOfPolygon = Generator("Sum of Angles of Polygon", 58, "Sum of angles of polygon with n sides = ", "sum", sumOfAnglesOfPolygonFunc)