Advertisement
Guest User

Untitled

a guest
Jul 29th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 3.41 KB | None | 0 0
  1. ;;;======================================================
  2. ;;;   Number Puzzle Problem
  3. ;;;    
  4. ;;;     Solves the number puzzle problem in which
  5. ;;;       BIHFAG
  6. ;;;      +CHECAG
  7. ;;;     =GIEADDG
  8. ;;;          
  9. ;;;
  10. ;;;     CLIPS Version 6.0 Example
  11. ;;;
  12. ;;;     To execute, merely load, reset and run.
  13. ;;;     This example takes alot of memory to execute.
  14. ;;;======================================================
  15.  
  16. (defrule startup
  17.   =>
  18.   (printout t t "The problem is" t t)
  19.   (printout t "   BIHFAG" t)
  20.   (printout t " + CHECAG" t)
  21.   (printout t "   ------" t)
  22.   (printout t " =GIEADDG" t t)
  23.   (set-strategy breadth  )
  24.   (assert (number 0)
  25.           (number 1)
  26.           (number 2)
  27.           (number 3)
  28.           (number 4)
  29.           (number 5)
  30.           (number 6)
  31.           (number 7)
  32.           (number 8)
  33.           (number 9)
  34.           (letter B)
  35.           (letter I)
  36.           (letter H)
  37.           (letter F)
  38.           (letter A)
  39.           (letter G)
  40.           (letter C)
  41.           (letter E)
  42.           (letter D)
  43.  )
  44. )
  45.  
  46. (defrule generate-combinations
  47.   (number ?x)
  48.   (letter ?a)
  49.   =>
  50.   (assert (combination ?a ?x))
  51. )
  52.  
  53. (defrule find-solution
  54. ;;--------------------------------------------------------
  55.   (combination G ?g)
  56.   (test (= (mod (+ ?g ?g) 10) ?g))
  57. ;;--------------------------------------------------------  
  58.   (combination A ?a&~?g)
  59.   (combination D ?d&~?a&~?g)
  60.   (test (= (mod (+ ?g ?g
  61.                    (* 10 ?a)
  62.                    (* 10 ?a)
  63.                 )
  64.         100)
  65.            (+ (* 10 ?d) ?g)))
  66. ;;--------------------------------------------------------
  67.   (combination F     ?f&~?d&~?a&~?g)
  68.   (combination C ?c&~?f&~?d&~?a&~?g)
  69. ;;  (combination J ?j&~?f&~?h&~?i&~?b&~?e&~?g)
  70.   (test (= (mod (+ ?g ?g
  71.                    (* 10 ?a) (* 10 ?a)
  72.                    (* 100 ?f) (* 100 ?c))
  73.                    1000)
  74.            (+ (* 100 ?d)(* 10 ?d) ?g)))
  75.  
  76.   (combination H ?h&~?c&~?f&~?d&~?a&~?g)
  77.   (combination E ?e&~h&~?c&~?f&~?d&~?a&~?g)
  78.   (test (= (+ ?g ?g
  79.                    (* 10 ?a) (* 10 ?a)
  80.                    (* 100 ?f) (* 100 ?c)
  81.                    (* 1000 ?h) (* 1000 ?e)
  82.                   ;; (* 10000 ?b) (* 10000 ?g)
  83.                   ;; (* 100000 ?a) (* 100000 ?j)
  84.             )
  85.            
  86.             (+
  87.             ;;(* 100000 ?b)(* 10000 ?b)
  88.                    (* 1000 ?a)(* 100 ?d)(* 10 ?d) ?g
  89.             )
  90.     )
  91.   )
  92.  
  93.   (combination I ?i&~?h&~?c&~?f&~?d&~?a&~?g)
  94.   (test (= (+ ?g ?g
  95.                    (* 10 ?a) (* 10 ?a)
  96.                    (* 100 ?f) (* 100 ?c)
  97.                    (* 1000 ?h) (* 1000 ?e)
  98.                    (* 10000 ?i) (* 10000 ?h)
  99.                   ;; (* 100000 ?a) (* 100000 ?j)
  100.             )
  101.            
  102.             (+
  103.             ;;(* 100000 ?b)
  104.             (* 10000 ?e) (* 1000 ?a) (* 100 ?d) (* 10 ?d) ?g
  105.             )
  106.     )
  107.   )
  108.  
  109.   (combination B ?b&~?i&~?h&~?c&~?f&~?d&~?a&~?g)
  110.   (test (= (+ ?g ?g
  111.                    (* 10 ?a) (* 10 ?a)
  112.                    (* 100 ?f) (* 100 ?c)
  113.                    (* 1000 ?h) (* 1000 ?e)
  114.                    (* 10000 ?i) (* 10000 ?h)
  115.                    (* 100000 ?b) (* 100000 ?c))
  116.             (+
  117.                 (* 1000000 ?g) (* 100000 ?i) (* 10000 ?e) (* 1000 ?a) (* 100 ?d) (* 10 ?d) ?g
  118.             )
  119.     )
  120.   )
  121.  
  122.  =>
  123.   (printout t "A Solution is:" t t)
  124.  
  125.  
  126.   (printout t "  B = " ?b t)
  127.   (printout t "  I = " ?i t)
  128.   (printout t "  H = " ?h t)
  129.   (printout t "  F = " ?f t)
  130.   (printout t "  A = " ?a t)
  131.   (printout t "  G = " ?g t)
  132.   (printout t "  C = " ?c t)
  133.   (printout t "  E = " ?e t)
  134.   (printout t "  D = " ?d t)
  135.   (printout t t)
  136.   (printout t "   " ?b ?i ?h ?f ?a ?g t)
  137.   (printout t " + " ?c ?h ?e ?c ?a ?g t)
  138.   (printout t "   " "------" t)
  139.   (printout t " = "?g ?i ?e ?a ?d ?d ?g t t)
  140. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement