Last active
December 11, 2015 22:59
-
-
Save swannodette/4673834 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use '[clojure.core.logic]) | |
(require '[clojure.core.logic.fd :as fd]) | |
(defn simple [] | |
(run* [x y] | |
(fd/in x y (fd/interval 0 9)) | |
(fd/eq | |
(= (+ x y) 9) | |
(= (+ (* 4 x) (* 2 y)) 24)))) | |
;; (simple) => [3 6] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:- use_module(library(clpfd)). | |
simple(Q) :- | |
Q = [X, Y], | |
4*X + 2*Y #= 24, | |
X + Y #= 9, | |
[X,Y] ins 0..9. | |
/* simple(Q). => Q = [3, 6] */ |
Aren't lines 6 (clj) and 3 inverted math operations? 4 * y vs 2 * y?
@bostonaholic updated to include the necessary imports in both examples. @jcolebrand good catch, fixed.
@mrb Oops thanks for spotting that, fixed.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what libraries must you first import for running the prolog version?