Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;;======================================================
- ;;; Number Puzzle Problem
- ;;;
- ;;; Solves the number puzzle problem in which
- ;;; BIHFAG
- ;;; +CHECAG
- ;;; =GIEADDG
- ;;;
- ;;;
- ;;; CLIPS Version 6.0 Example
- ;;;
- ;;; To execute, merely load, reset and run.
- ;;; This example takes alot of memory to execute.
- ;;;======================================================
- (defrule startup
- =>
- (printout t t "The problem is" t t)
- (printout t " BIHFAG" t)
- (printout t " + CHECAG" t)
- (printout t " ------" t)
- (printout t " =GIEADDG" t t)
- (set-strategy breadth )
- (assert (number 0)
- (number 1)
- (number 2)
- (number 3)
- (number 4)
- (number 5)
- (number 6)
- (number 7)
- (number 8)
- (number 9)
- (letter B)
- (letter I)
- (letter H)
- (letter F)
- (letter A)
- (letter G)
- (letter C)
- (letter E)
- (letter D)
- )
- )
- (defrule generate-combinations
- (number ?x)
- (letter ?a)
- =>
- (assert (combination ?a ?x))
- )
- (defrule find-solution
- ;;--------------------------------------------------------
- (combination G ?g)
- (test (= (mod (+ ?g ?g) 10) ?g))
- ;;--------------------------------------------------------
- (combination A ?a&~?g)
- (combination D ?d&~?a&~?g)
- (test (= (mod (+ ?g ?g
- (* 10 ?a)
- (* 10 ?a)
- )
- 100)
- (+ (* 10 ?d) ?g)))
- ;;--------------------------------------------------------
- (combination F ?f&~?d&~?a&~?g)
- (combination C ?c&~?f&~?d&~?a&~?g)
- ;; (combination J ?j&~?f&~?h&~?i&~?b&~?e&~?g)
- (test (= (mod (+ ?g ?g
- (* 10 ?a) (* 10 ?a)
- (* 100 ?f) (* 100 ?c))
- 1000)
- (+ (* 100 ?d)(* 10 ?d) ?g)))
- (combination H ?h&~?c&~?f&~?d&~?a&~?g)
- (combination E ?e&~h&~?c&~?f&~?d&~?a&~?g)
- (test (= (+ ?g ?g
- (* 10 ?a) (* 10 ?a)
- (* 100 ?f) (* 100 ?c)
- (* 1000 ?h) (* 1000 ?e)
- ;; (* 10000 ?b) (* 10000 ?g)
- ;; (* 100000 ?a) (* 100000 ?j)
- )
- (+
- ;;(* 100000 ?b)(* 10000 ?b)
- (* 1000 ?a)(* 100 ?d)(* 10 ?d) ?g
- )
- )
- )
- (combination I ?i&~?h&~?c&~?f&~?d&~?a&~?g)
- (test (= (+ ?g ?g
- (* 10 ?a) (* 10 ?a)
- (* 100 ?f) (* 100 ?c)
- (* 1000 ?h) (* 1000 ?e)
- (* 10000 ?i) (* 10000 ?h)
- ;; (* 100000 ?a) (* 100000 ?j)
- )
- (+
- ;;(* 100000 ?b)
- (* 10000 ?e) (* 1000 ?a) (* 100 ?d) (* 10 ?d) ?g
- )
- )
- )
- (combination B ?b&~?i&~?h&~?c&~?f&~?d&~?a&~?g)
- (test (= (+ ?g ?g
- (* 10 ?a) (* 10 ?a)
- (* 100 ?f) (* 100 ?c)
- (* 1000 ?h) (* 1000 ?e)
- (* 10000 ?i) (* 10000 ?h)
- (* 100000 ?b) (* 100000 ?c))
- (+
- (* 1000000 ?g) (* 100000 ?i) (* 10000 ?e) (* 1000 ?a) (* 100 ?d) (* 10 ?d) ?g
- )
- )
- )
- =>
- (printout t "A Solution is:" t t)
- (printout t " B = " ?b t)
- (printout t " I = " ?i t)
- (printout t " H = " ?h t)
- (printout t " F = " ?f t)
- (printout t " A = " ?a t)
- (printout t " G = " ?g t)
- (printout t " C = " ?c t)
- (printout t " E = " ?e t)
- (printout t " D = " ?d t)
- (printout t t)
- (printout t " " ?b ?i ?h ?f ?a ?g t)
- (printout t " + " ?c ?h ?e ?c ?a ?g t)
- (printout t " " "------" t)
- (printout t " = "?g ?i ?e ?a ?d ?d ?g t t)
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement