Rudy’s OBTF Rudolf Adamkovič

Home / Computer science / SAT solver / Practice implementation: Emacs Lisp


Search: Detecting solutions

(defun my-sat-solved-p (domains)
  "Return non-nil if DOMAINS contain the solution."
  (all (pcase-lambda (`(_variable . (_value ,other-value)))
         (not other-value))
       domains))
(ert-deftest my-sat-solved-p ()
  (should (my-sat-solved-p '())) ;; Trivially solved.
  (should (my-sat-solved-p '((1 . (0)))))
  (should (my-sat-solved-p '((1 . (0)) (2 . (1))))))

(ert-deftest my-sat-solved-p/nil ()
  (should-not (my-sat-solved-p '((1 . (0 1)) (2 . (1)))))
  (should-not (my-sat-solved-p '((1 . (0)) (2 . (0 1))))))

© 2025 Rudolf Adamkovič under GNU General Public License version 3.
Made with Emacs and secret alien technologies of yesteryear.