mirror of
https://github.com/DeaDvey/mathgenerator.git
synced 2025-11-28 14:35:23 +01:00
Fixed error where the problem is adjusted in the algorithm
This commit is contained in:
@@ -218,16 +218,17 @@ def multiplyIntToMatrix22(maxMatrixVal = 10, maxRes = 100):
|
|||||||
|
|
||||||
def primeFactors(minVal=10, maxVal=999):
|
def primeFactors(minVal=10, maxVal=999):
|
||||||
a = random.randint(minVal, maxVal)
|
a = random.randint(minVal, maxVal)
|
||||||
|
n = a
|
||||||
i = 2
|
i = 2
|
||||||
factors = []
|
factors = []
|
||||||
while i*i <= a:
|
while i * i <= n:
|
||||||
if a % i:
|
if n % i:
|
||||||
i += 1
|
i += 1
|
||||||
else:
|
else:
|
||||||
a //= i
|
n //= i
|
||||||
factors.append(i)
|
factors.append(i)
|
||||||
if a > 1:
|
if n > 1:
|
||||||
factors.append(a)
|
factors.append(n)
|
||||||
problem = f"Find prime factors of {a}"
|
problem = f"Find prime factors of {a}"
|
||||||
solution = f"{factors}"
|
solution = f"{factors}"
|
||||||
return problem, solution
|
return problem, solution
|
||||||
@@ -254,4 +255,7 @@ decimalToBinary = Generator("Decimal to Binary",14,"Binary of a=","b",DecimalToB
|
|||||||
binaryToDecimal = Generator("Binary to Decimal",15,"Decimal of a=","b",BinaryToDecimalFunc)
|
binaryToDecimal = Generator("Binary to Decimal",15,"Decimal of a=","b",BinaryToDecimalFunc)
|
||||||
fractionDivision = Generator("Fraction Division", 16, "(a/b)/(c/d)=", "x/y", divideFractionsFunc)
|
fractionDivision = Generator("Fraction Division", 16, "(a/b)/(c/d)=", "x/y", divideFractionsFunc)
|
||||||
intMatrix22Multiplication = Generator("Integer Multiplication with 2x2 Matrix", 17, "k * [[a,b],[c,d]]=", "[[k*a,k*b],[k*c,k*d]]", multiplyIntToMatrix22)
|
intMatrix22Multiplication = Generator("Integer Multiplication with 2x2 Matrix", 17, "k * [[a,b],[c,d]]=", "[[k*a,k*b],[k*c,k*d]]", multiplyIntToMatrix22)
|
||||||
primeFactors = Generator("Prime Factorisation", 18, "Prime Factors of a =", "[b, c, d, ...]", primeFactors)
|
primeFactors = Generator("Prime Factorisation", 18, "Prime Factors of a =", "[b, c, d, ...]", primeFactors)
|
||||||
|
|
||||||
|
for i in range(0, 10):
|
||||||
|
print(primeFactors())
|
||||||
Reference in New Issue
Block a user