Mjahaja
This commit is contained in:
		| @ -19,9 +19,40 @@ | ||||
|     (((? x)) | ||||
|         (map (lambda (y) (list y)) x)) | ||||
|     (((? x) . (? xs)) | ||||
|      (if (list? x) | ||||
|         (zipWith | ||||
|             cons | ||||
|             x | ||||
|             (transpose xs))))) | ||||
|             (transpose xs)) | ||||
|         ('error))) | ||||
|     (_ 'error))) | ||||
|  | ||||
| (defun getCol (grid x) (getRow (transpose grid) x)) | ||||
|  | ||||
| (defun MatrixToList (m) (foldr append nil m)) | ||||
|  | ||||
| (defun getSubMatrix (m startcol stopcol startrow stoprow) | ||||
|   (let ((f (lambda (x start stop) (take (drop x start) (- (+ 1 stop) start))))) | ||||
|    (map (lambda (x) (f x startcol stopcol)) (f m startrow stoprow)))) | ||||
|  | ||||
|  | ||||
| (defun getSubGridAsList (m x) | ||||
|   (if (and (>= x 0) (< x 9)) | ||||
|       (let ((sr (* (// x 3) 3)) | ||||
|             (er (+ sr 2)) | ||||
|             (sc (* (mod x 3) 3)) | ||||
|             (ec (+ sc 2))) | ||||
|         (matrixToList (getSubMatrix m sr er sc ec))) | ||||
|       'error)) | ||||
|  | ||||
| (define exampleGrid | ||||
|   '( | ||||
|     (1 2 3 4 5 6 7 8 9) | ||||
|     (2 3 4 5 6 7 8 9 1) | ||||
|     (3 4 5 6 7 8 9 1 2) | ||||
|     (4 5 6 7 8 9 1 2 3) | ||||
|     (5 6 7 8 9 1 2 3 4) | ||||
|     (6 7 8 9 1 2 3 4 5) | ||||
|     (7 8 9 1 2 3 4 5 6) | ||||
|     (8 9 1 2 3 4 5 6 7) | ||||
|     (9 1 2 3 4 5 6 7 8))) | ||||
|  | ||||
		Reference in New Issue
	
	Block a user