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 time | ||||||
| import random | 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 | # in function to take arbitrary matrix input from user | ||||||
| def inmat(rowcol) : | def inmat(rowcol) : | ||||||
|     # initialise list of lists |     # initialise list of lists | ||||||
| @ -70,13 +78,8 @@ def practice(t) : | |||||||
| 
 | 
 | ||||||
|     # infinite loop of practice |     # infinite loop of practice | ||||||
|     while True : |     while True : | ||||||
|         # generate a random matrices |         a = genmatrix(rowcol, intmax, dif) | ||||||
|         a = sp.randMatrix(rowcol, rowcol, 0, intmax) |         b = genmatrix(rowcol, intmax, dif) | ||||||
|         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() |  | ||||||
| 
 | 
 | ||||||
|         # infinite loop until user succeeds  |         # infinite loop until user succeeds  | ||||||
|         while True : |         while True : | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user