X-Git-Url: https://git.rkrishnan.org/?p=sicp.git;a=blobdiff_plain;f=src%2Fsicp%2Flogic-puzzles.rkt;fp=src%2Fsicp%2Flogic-puzzles.rkt;h=52a5f48228f4e151e8ccb2c0e7054aa990fc3b9c;hp=0000000000000000000000000000000000000000;hb=273f2bd230187a3164803ac32d9b5734d0123ad0;hpb=c3062a9e8691e9c067b69ec24a728c746520b310 diff --git a/src/sicp/logic-puzzles.rkt b/src/sicp/logic-puzzles.rkt new file mode 100644 index 0000000..52a5f48 --- /dev/null +++ b/src/sicp/logic-puzzles.rkt @@ -0,0 +1,26 @@ +#lang racket + +(require "amb-eli.rkt") +(require "distinct.rkt") + +(define (multiple-dwelling) + (let [(baker (amb 1 2 3 4 5)) + (cooper (amb 1 2 3 4 5)) + (fletcher (amb 1 2 3 4 5)) + (miller (amb 1 2 3 4 5)) + (smith (amb 1 2 3 4 5))] + (assert (distinct? (list baker cooper fletcher miller smith))) + (assert (not (= baker 5))) + (assert (not (= cooper 1))) + (assert (not (= fletcher 5))) + (assert (not (= fletcher 1))) + (assert (> miller cooper)) + (assert (not (= (abs (- smith fletcher)) 1))) + (assert (not (= (abs (- fletcher cooper)) 1))) + (list (list 'baker baker) + (list 'cooper cooper) + (list 'fletcher fletcher) + (list 'miller miller) + (list 'smith smith)))) + +(multiple-dwelling) \ No newline at end of file