Matthew Butterick 6 years ago
parent e25a4b5fed
commit d09b084b52

@ -0,0 +1,29 @@
#lang br
(require csp sugar)
(define triples (make-csp))
(add-var! triples 'a (range 10 50))
(add-var! triples 'b (range 10 50))
(add-var! triples 'c (range 10 50))
(define (valid-triple? x y z)
(= (expt z 2) (+ (expt x 2) (expt y 2))))
(add-constraint! triples valid-triple? '(a b c))
(require math/number-theory)
(add-constraint! triples coprime? '(a b c))
(add-constraint! triples <= '(a b))
(time-avg 10 (solve* triples))
(define (f)
(for*/list ([a (in-range 10 50)]
[b (in-range 10 50)]
#:when (<= a b)
[c (in-range 10 50)]
#:when (and (coprime? a b c) (valid-triple? a b c)))
`((a . ,a) (b . ,b) (c . ,c))))
(time-avg 10 (f))

@ -489,7 +489,7 @@
#:select-variable [select-unassigned-variable
(or (current-select-variable) first-unassigned-variable)]
#:order-values [order-domain-values (or (current-order-values) first-domain-value)]
#:inference [inference (or (current-inference) no-inference)])
#:inference [inference (or (current-inference) forward-check)])
((csp?) (#:select-variable procedure? #:order-values procedure? #:inference procedure?) . ->* . generator?)
(generator ()
(define reduce-arity-proc (if (current-arity-reduction) reduce-constraint-arity values))

Loading…
Cancel
Save