From 7f66db8e3f67f57b6089dc1b61d904f80ee48a61 Mon Sep 17 00:00:00 2001 From: Ritu Raj <68614399+Ritu1611@users.noreply.github.com> Date: Fri, 16 Oct 2020 23:17:27 +0530 Subject: [PATCH] Update mathgen.py Number of Permutations. --- mathgenerator/mathgen.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 16f7537..6d39a65 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -386,6 +386,18 @@ def primeFactors(minVal=1, maxVal=200): problem = f"Find prime factors of {a}" solution = f"{factors}" return problem, solution +def permutationFunc(maxlength=20): + def factorial(a): + d=1 + for i in range(a): + a=(i+1)*d + d=a + return d + a= random.randint(10,maxlength) + b=random.randint(0,9) + solution= int(factorial(a)/(factorial(a-b))) + problem= "Number of combinations from {} objects picked {} at a time = ".format(a,b) + return problem, solution # || Class Instances @@ -419,4 +431,5 @@ systemOfEquations = Generator("Solve a System of Equations in R^2", 23, "2x + 5y 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) 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 -primeFactors = Generator("Prime Factorisation", 27, "Prime Factors of a =", "[b, c, d, ...]", primeFactors) \ No newline at end of file +primeFactors = Generator("Prime Factorisation", 27, "Prime Factors of a =", "[b, c, d, ...]", primeFactors) +permutations= Generator("Permutations",28, "Total permutations of 4 objects at a time from 10 objects is","5040", permutationFunc)