Feynman Division using scheme's amb
;; Author: Carlos Perilla
;; Date: 25-10-2013
;; See: http://programmingpraxis.com/2009/06/12/feynmans-puzzle/
;; Your task is to solve Feynman’s Puzzle.
;; http://programmingpraxis.files.wordpress.com/2009/06/r3brp.jpg
(require-library amb)
(import amb)
(use srfi-1)
(define (required x) (amb-assert x))
(define (build-decimal list) (fold (lambda (x acc) (+ (* acc 10) x)) 0 list))
(let ((a (amb 0 1 2 3 4 5 6 7 8 9))
(b (amb 0 1 2 3 4 5 6 7 8 9))
(c (amb 0 1 2 3 4 5 6 7 8 9))
(d (amb 0 1 2 3 4 5 6 7 8 9))
(e (amb 0 1 2 3 4 5 6 7 8 9))
(f (amb 0 1 2 3 4 5 6 7 8 9))
)
(required (not (= a b)))
(required (not (= a c)))
(required (not (= a d)))
(required (not (= a e)))
(required (not (= a f)))
(required (< e d))
(required (= (modulo (quotient (* (+ (* 1000 d) (* e 100) (* a 10) f)
(+ (* 100 b) (* 10 a) c) ) 100) 10) a))
(required (= (modulo (* d (+ (* 100 b) (* 10 a) c)) 100) (+ (* 10 a) a) ))
(required (= (modulo (* e (+ (* 100 b) (* 10 a) c)) 10) a ))
(required (= (modulo (quotient (* a (+ (* 100 b) (* 10 a) c)) 100) 10) a ))
(list (list b a c) (list d e a f)))