This commit is contained in:
2025-10-14 13:44:10 +02:00
parent ebf47cb9bf
commit 4ee87094cc

View File

@ -19,9 +19,40 @@
(((? x)) (((? x))
(map (lambda (y) (list y)) x)) (map (lambda (y) (list y)) x))
(((? x) . (? xs)) (((? x) . (? xs))
(if (list? x)
(zipWith (zipWith
cons cons
x x
(transpose xs))))) (transpose xs))
('error)))
(_ 'error)))
(defun getCol (grid x) (getRow (transpose grid) x)) (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)))