tehee
This commit is contained in:
@ -27,6 +27,17 @@
|
||||
(defun amount (x y)
|
||||
(foldr (lambda (z q) (if (eq x z) (+ q 1) q)) 0 y))
|
||||
|
||||
(defun in (x xs) (foldr (lambda (y z) (if (eq x y) t z)) nil xs))
|
||||
|
||||
(defun intersection (xs ys) (filter (lambda (x) (in x ys)) xs))
|
||||
|
||||
(defun repeat (x e)
|
||||
(if (number? x)
|
||||
(match x
|
||||
(0 nil)
|
||||
(_ (cons e (repeat (- x 1) e))))
|
||||
'error))
|
||||
|
||||
(defun valid (x)
|
||||
(if (= 9 (length x))
|
||||
(foldr
|
||||
@ -35,8 +46,36 @@
|
||||
(map (lambda (y) (amount y x)) nums))
|
||||
nil))
|
||||
|
||||
(defun notPresentRow (xs)
|
||||
(foldr
|
||||
(lambda (x ys) (if (in x xs) ys (cons x ys)))
|
||||
nil
|
||||
nums))
|
||||
|
||||
(defun notPresent (grid row col)
|
||||
(intersection (notPresentRow (getRow grid row))
|
||||
(notPresentRow (getCol grid col))))
|
||||
|
||||
(defun getRow (grid x) (ix grid x))
|
||||
|
||||
(defun findEmpty (grid)
|
||||
(foldr (lambda (zs ys)
|
||||
(match zs
|
||||
(((?row) . (?rowVal))
|
||||
(append
|
||||
(zip
|
||||
(repeat 9 row)
|
||||
(foldr (lambda (x qs)
|
||||
(match x
|
||||
(((?col) . (?val)) (if (eq val nil) (cons col qs) qs))
|
||||
(_ 'error)))
|
||||
nil
|
||||
(zip (iota 9) rowVal)))
|
||||
ys))
|
||||
(_ 'error)))
|
||||
nil
|
||||
(zip (iota 9) grid)))
|
||||
|
||||
(defun transpose (grid)
|
||||
(match grid
|
||||
(nil nil)
|
||||
|
||||
Reference in New Issue
Block a user