diff --git a/README.md b/README.md index dfc7d41..a8c09dc 100644 --- a/README.md +++ b/README.md @@ -56,8 +56,7 @@ problem, solution = mathgen.genById(0) | 23 | Solve a System of Equations in R^2 | 4x - 8y = 48, 3x - 8y = 40 | x = 8, y = -2 | systemOfEquations | | 24 | Distance between 2 points | Find the distance between (-9, -20) and (18, -19) | sqrt(730) | distance2Point | | 25 | Pythagorean Theorem | The hypotenuse of a right triangle given the other two lengths 18 and 13 = | 22.20 | pythagoreanTheorem | -| 26 | Linear Equations | -11x + -16y = -302 -1x + 20y = 250 | x = 10, y = 12 | linearEquations | +| 26 | Linear Equations | -11x + -16y = -302 , 1x + 20y = 250 | x = 10, y = 12 | linearEquations | | 27 | Prime Factorisation | Find prime factors of 55 | [5, 11] | primeFactors | | 28 | Fraction Multiplication | (4/9)*(8/10) | 16/45 | fractionMultiplication | | 29 | Angle of a Regular Polygon | Find the angle of a regular polygon with 15 sides | 156.0 | angleRegularPolygon | @@ -79,5 +78,5 @@ problem, solution = mathgen.genById(0) | 45 | Simple Interest | Simple interest for a principle amount of 6128 dollars, 5% rate of interest and for a time period of 5 years is = | 1532.0 | simpleInterest | | 46 | Multiplication of two matrices | Multiply [[-20, -14, -88, -62, 39, 94, 21, 75, 26], [89, -67, -80, -60, 32, -23, -79, 11, -69], [13, -75, -66, 3, 67, -79, -49, 6, 36], [-44, -84, 68, -27, -86, -95, -71, -77, -62], [45, 58, 89, 82, 30, -83, -23, 51, 95], [11, 46, 100, -15, 60, -34, 85, 50, -44], [93, -100, -62, 63, -73, -64, 90, -15, 23], [-8, 91, -22, 53, -42, 25, 32, -26, 31], [-60, 90, 75, -42, 19, 33, -30, 74, 13]] and [[-80, 54, -39, 37, -99], [31, -28, -31, 64, 73], [-21, -34, -28, -21, -76], [-94, 55, 66, 0, 17], [-28, 25, -65, -74, 100], [76, 74, -96, -98, -5], [-90, -70, -66, -71, -35], [65, 49, -100, 72, -23], [-95, -97, -31, -84, -86]] | [[15409, 6508, -21665, -10161, 5326], [9859, 17962, 3267, 12768, 3119], [-8761, 1272, 8611, 738, 3881], [4489, -5790, 29652, 11947, -5940], [-22167, -8208, -1142, 6747, -10714], [-4628, -5167, -15527, 1404, 243], [-29240, -2432, 11103, 615, -22487], [-5498, -5038, 1462, -100, 2495], [18214, -3238, -15548, 3691, 6061]] | matrixMultiplication | | 47 | Cube Root | cuberoot of 711 upto 2 decimal places is: | 8.93 | CubeRoot | -| 48 | Power Rule Integration | 3x^1 | (3/1)x^2 + c | powerRuleIntegration | +| 48 | Power Rule Integration | 3x^1 | (3/2)x^2 + c | powerRuleIntegration | | 49 | Fourth Angle of Quadrilateral | Fourth angle of quadrilateral with angles 94 , 101, 102 = | 63 | fourthAngleOfQuadrilateral | diff --git a/mathgenerator/__pycache__/mathgen.cpython-37.pyc b/mathgenerator/__pycache__/mathgen.cpython-37.pyc index 418e0a5..82bcec4 100644 Binary files a/mathgenerator/__pycache__/mathgen.cpython-37.pyc and b/mathgenerator/__pycache__/mathgen.cpython-37.pyc differ diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index d00ea30..3c91834 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -699,7 +699,7 @@ def powerRuleIntegrationFunc(maxCoef = 10, maxExp = 10, maxTerms = 5): coefficient = random.randint(1, maxCoef) exponent = random.randint(1, maxExp) problem += str(coefficient) + "x^" + str(exponent) - solution += "("+str(coefficient) +"/"+str(exponent) +")x^" + str(exponent +1) + solution += "("+str(coefficient) +"/"+str(exponent + 1) +")x^" + str(exponent +1) solution = solution + " + c" return problem, solution @@ -713,6 +713,125 @@ def fourthAngleOfQuadriFunc(maxAngle = 180): problem = f"Fourth angle of quadrilateral with angles {angle1} , {angle2}, {angle3} =" solution = angle4 return problem, solution + +def quadraticEquation(maxVal=100): + a = random.randint(1,maxVal) + c = random.randint(1,maxVal) + b = random.randint(round(math.sqrt(4*a*c))+1,round(math.sqrt(4*maxVal*maxVal))) + + problem = "Zeros of the Quadratic Equation {}x^2+{}x+{}=0".format(a,b,c) + + D = math.sqrt(b*b-4*a*c) + + solution = str([round((-b+D)/(2*a), 2),round((-b-D)/(2*a), 2)]) + return problem,solution + +def hcfFunc(maxVal=20): + a = random.randint(1, maxVal) + b = random.randint(1, maxVal) + x, y = a, b + while(y): + x, y = y, x % y + problem = f"HCF of {a} and {b} = " + solution = str(x) + return problem, solution + +def DiceSumProbFunc(maxDice=3): + a = random.randint(1,maxDice) + b = random.randint(a,6*a) + count=0 + for i in [1,2,3,4,5,6]: + if a==1: + if i==b: + count=count+1 + elif a==2: + for j in [1,2,3,4,5,6]: + if i+j==b: + count=count+1 + elif a==3: + for j in [1,2,3,4,5,6]: + for k in [1,2,3,4,5,6]: + if i+j+k==b: + count=count+1 + problem = "If {} dice are rolled at the same time, the probability of getting a sum of {} =".format(a,b) + solution="{}/{}".format(count, 6**a) + return problem, solution + +def exponentiationFunc(maxBase = 20,maxExpo = 10): + base = random.randint(1, maxBase) + expo = random.randint(1, maxExpo) + problem = f"{base}^{expo} =" + solution = str(base ** expo) + return problem, solution + +def confidenceIntervalFunc(): + n=random.randint(20,40) + j=random.randint(0,3) + lst=random.sample(range(200,300),n) + lst_per=[80 ,90, 95, 99] + lst_t = [1.282, 1.645, 1.960, 2.576] + mean=0 + sd=0 + for i in lst: + count= i + mean + mean=count + mean = mean/n + for i in lst: + x=(i-mean)**2+sd + sd=x + sd=sd/n + standard_error = lst_t[j]*math.sqrt(sd/n) + problem= 'The confidence interval for sample {} with {}% confidence is'.format([x for x in lst], lst_per[j]) + solution= '({}, {})'.format(mean+standard_error, mean-standard_error) + return problem, solution + +def surdsComparisonFunc(maxValue = 100, maxRoot = 10): + radicand1,radicand2 = tuple(random.sample(range(1,maxValue),2)) + degree1, degree2 = tuple(random.sample(range(1,maxRoot),2)) + problem = f"Fill in the blanks {radicand1}^(1/{degree1}) _ {radicand2}^(1/{degree2})" + first = math.pow(radicand1, 1/degree1) + second = math.pow(radicand2, 1/degree2) + solution = "=" + if first > second: + solution = ">" + elif first < second: + solution = "<" + return problem, solution + +def fibonacciSeriesFunc(minNo=1): + n = random.randint(minNo,20) + def createFibList(n): + l=[] + for i in range(n): + if i<2: + l.append(i) + else: + val = l[i-1]+l[i-2] + l.append(val) + return l + fibList=createFibList(n) + problem = "The Fibonacci Series of the first "+str(n)+" numbers is ?" + solution = fibList + return problem,solution + +def basicTrigonometryFunc(angles=[0,30,45,60,90],functions=["sin","cos","tan"]): #Handles degrees in quadrant one + angle=random.choice(angles) + function=random.choice(functions) + + problem=f"What is {function}({angle})?" + expression='math.'+function+'(math.radians(angle))' + result_fraction_map={0.0:"0",0.5:"1/2",0.71:"1/√2",0.87:"√3/2",1.0:"1",0.58:"1/√3",1.73:"√3"} + + solution=result_fraction_map[round(eval(expression),2)] if round(eval(expression),2)<=99999 else "∞" #for handling the ∞ condition + + return problem,solution + +def sumOfAnglesOfPolygonFunc(maxSides = 12): + side = random.randint(3, maxSides) + sum = (side - 2) * 180 + problem = f"Sum of angles of polygon with {side} sides = " + solution = sum + return problem, solution # || Class Instances @@ -766,31 +885,14 @@ compareFractions=Generator("Compare Fractions",44,"Which symbol represents the c simpleInterest = Generator("Simple Interest", 45, "Simple interest for a principle amount of a dollars, b% rate of interest and for a time period of c years is = ", "d dollars", simpleInterestFunc) matrixMultiplication = Generator("Multiplication of two matrices", 46, "Multiply two matrices A and B", "C", matrixMultiplicationFunc) CubeRoot = Generator("Cube Root",47,"Cuberoot of a upto 2 decimal places is","b",cubeRootFunc) -powerRuleIntegration = Generator("Power Rule Integration", 48, "nx^m=", "(n/m)x^(m+1)", powerRuleIntegrationFunc) +powerRuleIntegration = Generator("Power Rule Integration", 48, "nx^m=", "(n/m+1)x^(m+1)", powerRuleIntegrationFunc) fourthAngleOfQuadrilateral = Generator("Fourth Angle of Quadrilateral",49,"Fourth angle of Quadrilateral with angles a,b,c =","angle4",fourthAngleOfQuadriFunc) - -wList = getGenList() -#print(wList) -allRows = [] -f=open('mathgen.py') -lines=f.readlines() -line = 720 -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() - print(def_name) - row = [myGen.id, myGen.title, prob, sol, def_name] - print(row) - 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) - #print(tableLine) -g.close() +quadraticEquationSolve = Generator("Quadratic Equation", 50, "Find the zeros {x1,x2} of the quadratic equation ax^2+bx+c=0", "x1,x2", quadraticEquation) +hcf = Generator("HCF (Highest Common Factor)", 51, "HCF of a and b = ", "c", hcfFunc) +diceSumProbability=Generator("Probability of a certain sum appearing on faces of dice", 52,"If n dices are rolled then probabilty of getting sum of x is =","z", DiceSumProbFunc) +exponentiation = Generator("Exponentiation", 53,"a^b = ","c",exponentiationFunc) +confidenceInterval = Generator("Confidence interval For sample S", 54, "With X% confidence", "is (A,B)", confidenceIntervalFunc) +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) +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) \ No newline at end of file