Skip to content

Commit

Permalink
Merge pull request mingchuno#59 from mukeshtiwari/master
Browse files Browse the repository at this point in the history
clojure solution using core.logic as contraint satisfaction problem
  • Loading branch information
gaplo917 committed Mar 28, 2016
2 parents 524287e + 0a8a879 commit ec417ef
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
28 changes: 28 additions & 0 deletions clojure-constraint-solver/abcdefghppp.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
(ns constraint-prog.core
(:require [clojure.core.logic :refer :all]
[clojure.core.logic.fd :as fd])
(:refer-clojure :exclude [==])
(:gen-class))




(defn define-constraint [lo hi]
(run* [q]
(fresh [a b c d e f g h p]
(fd/in a b c d e f g h p (fd/interval lo hi))
(fd/distinct [a b c d e f g h p])
(fd/eq
(!= a 0)
(!= c 0)
(!= e 0)
(!= g 0)
(= (+ (* 10 e) f)
(- (+ (* 10 a) b)
(+ (* 10 c) d)))
(= (* 111 p)
(+ (+ (* 10 e) f)
(+ (* 10 g) h))))
(== q [a b c d e f g h p]))))


4 changes: 4 additions & 0 deletions clojure-constraint-solver/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
constraint-prog.core> (define-constraint 0 9)
([9 0 2 7 6 3 4 8 1] [9 0 6 3 2 7 8 4 1] [8 5 4 6 3 9 7 2 1] [9 5 2 7 6 8 4 3 1] [8 6 5 4 3 2 7 9 1])

;; evaluate the buffer (C-c C-k).

0 comments on commit ec417ef

Please sign in to comment.