Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,27 @@
(require 'hash)
(require' amb)
;;
;; Solver
;;
(define (dwelling-puzzle context names floors H)
;; each amb calls gives a floor to a name
(for ((name names))
(hash-set H name (amb context floors)))
;; They live on different floors.
(amb-require (distinct? (amb-choices context)))
(constraints floors H) ;; may fail and backtrack
;; result returned to amb-run
(for/list ((name names))
(cons name (hash-ref H name)))
;; (amb-fail) is possible here to see all solutions
)
(define (task names)
(amb-run dwelling-puzzle
(amb-make-context)
names
(iota (length names)) ;; list of floors : 0,1, ....
(make-hash)) ;; hash table : "name" -> floor
)

View file

@ -0,0 +1,21 @@
(define names '("baker" "cooper" "fletcher" "miller" "smith" ))
(define-syntax-rule (floor name) (hash-ref H name))
(define-syntax-rule (touch a b) (= (abs (- (hash-ref H a) (hash-ref H b))) 1))
(define (constraints floors H)
(define top (1- (length floors)))
;; Baker does not live on the top floor.
(amb-require (!= (floor "baker") top))
;; Cooper does not live on the bottom floor.
(amb-require (!= (floor "cooper") 0))
;; Fletcher does not live on either the top or the bottom floor.
(amb-require (!= (floor "fletcher") top))
(amb-require (!= (floor "fletcher") 0))
;; Miller lives on a higher floor than does Cooper.
(amb-require (> (floor "miller") (floor "cooper")))
;; Smith does not live on a floor adjacent to Fletcher's.
(amb-require (not (touch "smith" "fletcher")))
;; Fletcher does not live on a floor adjacent to Cooper's.
(amb-require (not (touch "fletcher" "cooper")))
)

View file

@ -0,0 +1,2 @@
(task names)
→ ((baker . 2) (cooper . 1) (fletcher . 3) (miller . 4) (smith . 0))

View file

@ -0,0 +1,13 @@
;; add a name/floor
(define names '("baker" "cooper" "fletcher" "miller" "smith" "antoinette"))
(define (constraints floors H)
;; ... same as above, add the following
;; Antoinette does not like 💔 Smith
(amb-require (not (touch "smith" "antoinette")))
;; Antoinette is very close ❤️ to Cooper
(amb-require (touch "cooper" "antoinette"))
;; Antoinette wants a prime numbered floor
(amb-require (prime? (floor "antoinette")))
)

View file

@ -0,0 +1,2 @@
(task names)
→ ((baker . 0) (cooper . 1) (fletcher . 3) (miller . 4) (smith . 5) (antoinette . 2))