home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / clips_2 / CLIPS / Examples / Wordgame < prev    next >
Encoding:
Text File  |  1993-06-02  |  2.9 KB  |  105 lines

  1.  
  2. ;;;======================================================
  3. ;;;   Number Puzzle Problem
  4. ;;;     
  5. ;;;     Solves the number puzzle problem in which
  6. ;;;
  7. ;;;          GERALD 
  8. ;;;        + DONALD
  9. ;;;          ------
  10. ;;;        = ROBERT
  11. ;;;
  12. ;;;     CLIPS Version 6.0 Example
  13. ;;;
  14. ;;;     To execute, merely load, reset and run.
  15. ;;;     This example takes alot of memory to execute.
  16. ;;;======================================================
  17.  
  18. (defrule startup
  19.   =>
  20.   (printout t t "The problem is" t t)
  21.   (printout t "   GERALD" t)
  22.   (printout t " + DONALD" t)
  23.   (printout t "   ------" t)
  24.   (printout t " = ROBERT" t t)
  25.   (assert (number 0)
  26.           (number 1)
  27.           (number 2)
  28.           (number 3)
  29.           (number 4)
  30.           (number 5)
  31.           (number 6)
  32.           (number 7)
  33.           (number 8)
  34.           (number 9)
  35.           (letter G)
  36.           (letter E)
  37.           (letter R)
  38.           (letter A)
  39.           (letter L)
  40.           (letter D)
  41.           (letter O)
  42.           (letter N)
  43.           (letter B)
  44.           (letter T)))
  45.  
  46. (defrule generate-combinations
  47.   (number ?x)
  48.   (letter ?a)
  49.   =>
  50.   (assert (combination ?a ?x)))
  51.  
  52. (defrule find-solution
  53.   (combination D ?d)
  54.   (combination T ?t&~?d)
  55.   (test (= (mod (+ ?d ?d) 10) ?t))
  56.   (combination L ?l&~?d&~?t)
  57.   (combination R ?r&~?d&~?t&~?l)
  58.   (test (= (mod (+ ?d ?d
  59.                    (* 10 ?l) (* 10 ?l))
  60.                 100)
  61.            (+ (* 10 ?r) ?t)))
  62.   (combination A ?a&~?d&~?t&~?l&~?r)
  63.   (combination E ?e&~?d&~?t&~?l&~?r&~?a)
  64.   (test (= (mod (+ ?d ?d
  65.                    (* 10 ?l) (* 10 ?l)
  66.                    (* 100 ?a) (* 100 ?a))
  67.                 1000)
  68.            (+ (* 100 ?e) (* 10 ?r) ?t)))
  69.   (combination N ?n&~?d&~?t&~?l&~?r&~?a&~?e)
  70.   (combination B ?b&~?d&~?t&~?l&~?r&~?a&~?e&~?n)
  71.   (test (= (mod (+ ?d ?d
  72.                    (* 10 ?l) (* 10 ?l)
  73.                    (* 100 ?a) (* 100 ?a)
  74.                    (* 1000 ?r) (* 1000 ?n))
  75.                 10000)
  76.            (+ (* 1000 ?b) (* 100 ?e) (* 10 ?r) ?t)))
  77.   (combination O ?o&~?d&~?t&~?l&~?r&~?a&~?e&~?n&~?b)
  78.   (combination G ?g&~?d&~?t&~?l&~?r&~?a&~?e&~?n&~?b&~?o)
  79.   (test (= (+ ?d ?d
  80.               (* 10 ?l) (* 10 ?l)
  81.               (* 100 ?a) (* 100 ?a)
  82.               (* 1000 ?r) (* 1000 ?n)
  83.               (* 10000 ?e) (* 10000 ?o)
  84.               (* 100000 ?g) (* 100000 ?d))
  85.            (+ (* 100000 ?r) (* 10000 ?o) (* 1000 ?b) (* 100 ?e) (* 10 ?r) ?t)))
  86.   =>
  87.   (printout t "A Solution is:" t t)
  88.   (printout t "  G = " ?g t)
  89.   (printout t "  E = " ?e t)
  90.   (printout t "  R = " ?r t)
  91.   (printout t "  A = " ?a t)
  92.   (printout t "  L = " ?l t)
  93.   (printout t "  D = " ?d t)
  94.   (printout t "  O = " ?o t)
  95.   (printout t "  N = " ?n t)
  96.   (printout t "  B = " ?b t)
  97.   (printout t "  T = " ?t t)
  98.   (printout t t)
  99.   (printout t "   " ?g ?e ?r ?a ?l ?d t)
  100.   (printout t " + " ?d ?o ?n ?a ?l ?d t) 
  101.   (printout t "   " "------" t)
  102.   (printout t " = " ?r ?o ?b ?e ?r ?t t t))  
  103.   
  104.  
  105.