From cff9a6d71e63e5d1b6bafe3e9d96d7d7d6126e48 Mon Sep 17 00:00:00 2001 From: pingu Date: Tue, 14 Oct 2025 14:39:29 +0200 Subject: [PATCH] tehee --- sudoku.lispbm | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/sudoku.lispbm b/sudoku.lispbm index ffe5140..ebac75c 100644 --- a/sudoku.lispbm +++ b/sudoku.lispbm @@ -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)