Not working at the moment

This commit is contained in:
2025-10-14 17:17:32 +02:00
parent 8974eed235
commit 6d66ecafac

View File

@ -38,6 +38,14 @@
(_ (cons e (repeat (- x 1) e))))
'error))
(defun replace (lst i e)
(match lst
(((?x) . (?xs)) (match i
(0 (cons e xs))
(_ (cons x (replace xs (- i 1) e)))))
(nil nil)))
(defun valid (x)
(if (= 9 (length x))
(foldr
@ -90,6 +98,10 @@
('error)))
(_ 'error)))
(defun place (m r c e)
(let ((row (getRow m r)) (updatedRow (replace row c e)))
(replace m r updatedRow)))
(defun getCol (grid x) (getRow (transpose grid) x))
(defun MatrixToList (m) (foldr append nil m))
@ -106,3 +118,24 @@
(ec (+ sc 2)))
(matrixToList (getSubMatrix m sr er sc ec)))
'error))
(defun solve (grid)
(let ((empties (findEmpty grid))
(size1 (foldr
(lambda (x ys)
(let ((e (match x
(((?r) (?c)) (notPresent r c)))))
(if (= 1 (length e))
(cons (append e x) ys)
ys)))
nil
empties)))
(if (eq empties nil)
grid
(if (eq size1 nil)
() ; TODO: Empty
(solve (foldr (lambda (x gs)
(match x
((?e) (?r) (?c)) (place g r c e)))
grid size1))
))))