abstracted random matrix generation to a separate function genmatrix
This commit is contained in:
parent
a70b6fd0b7
commit
5b7c29a262
@ -2,6 +2,14 @@ import sympy as sp
|
||||
import time
|
||||
import random
|
||||
|
||||
def genmatrix(rowcol, intmax, dif) :
|
||||
# generate a random matrices
|
||||
a = sp.randMatrix(rowcol, rowcol, 0, intmax)
|
||||
# if determinant non-zero, radnom value less than difficulty, set a to its inverse
|
||||
if a.det() != 0 and random.random() <= dif :
|
||||
a = a.inv()
|
||||
return a
|
||||
|
||||
# in function to take arbitrary matrix input from user
|
||||
def inmat(rowcol) :
|
||||
# initialise list of lists
|
||||
@ -70,13 +78,8 @@ def practice(t) :
|
||||
|
||||
# infinite loop of practice
|
||||
while True :
|
||||
# generate a random matrices
|
||||
a = sp.randMatrix(rowcol, rowcol, 0, intmax)
|
||||
b = sp.randMatrix(rowcol, rowcol, 0, intmax)
|
||||
|
||||
# if determinant non-zero, radnom value less than difficulty, set a to its inverse
|
||||
if a.det() != 0 and random.random() <= dif :
|
||||
a = a.inv()
|
||||
a = genmatrix(rowcol, intmax, dif)
|
||||
b = genmatrix(rowcol, intmax, dif)
|
||||
|
||||
# infinite loop until user succeeds
|
||||
while True :
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user