amb-demo.scm

;;;; amb-demo.scm
;;;; A solution for the Kalotan puzzle using amb 

(require-extension amb)

(define (xor a? b?)
  (if (and a? b?) #f (or a? b?)))

(define (solve-kalotan-puzzle)
  (let ((parent1 (amb 'm 'f))
	(parent2 (amb 'm 'f))
	(kibi (amb 'm 'f))
	(kibi-self-desc (amb 'm 'f))
	(kibi-lied? (amb #t #f)))
    (amb-assert
     (not (eq? parent1 parent2)))
    (if kibi-lied?
	(amb-assert
	 (xor
	  (and (eqv? kibi-self-desc 'm)
	       (eqv? kibi 'f))
	  (and (eqv? kibi-self-desc 'f)
	       (eqv? kibi 'm)))))
    (if (not kibi-lied?)
	(amb-assert
	 (xor
	  (and (eqv? kibi-self-desc 'm)
	       (eqv? kibi 'm))
	  (and (eqv? kibi-self-desc 'f)
	       (eqv? kibi 'f)))))
    (if (eqv? parent1 'm)
	(amb-assert
	 (and
	  (eqv? kibi-self-desc 'm)
	  (xor
	   (and (eqv? kibi 'f)
		(eqv? kibi-lied? #f))
	   (and (eqv? kibi 'm)
		(eqv? kibi-lied? #t))))))
    (if (eqv? parent1 'f)
	(amb-assert
	 (and
	  (eqv? kibi 'f)
	  (eqv? kibi-lied? #t))))
    (list parent1 parent2 kibi)))

(write (amb-collect (solve-kalotan-puzzle)))
(newline)

Generated by GNU enscript 1.6.1.