You are on page 1of 2

Pb3:

(assert(number 0)(number 1)(number 2)(number 3)(number 4)(number 5)


(number 6)(number 7)(number 8)(number 9)
(letter T)(letter W)(letter O)(letter F)(letter U)(letter R))
(deftemplate combination (slot letter(type SYMBOL))(slot number(type
INTEGER)))

(defrule generate-combinations
(number ?x)
(letter ?a)
=>
(assert (combination(letter ?a)(number ?x))))

(defrule find-solution
(combination (letter F)(number ?f&: (= 1 ?f)))
(combination (letter T)(number ?t&~?f&~5&~4&~3&~2&~1))
(combination (letter O)(number ?o&~?f&~?t&: (= (mod (+ ?t ?t) 10) ?o)))
(combination (letter R)(number ?r&~?f&~?o&~?t&: (= (mod(+ ?o ?o) 10)?r)))
(combination (letter W)(number ?w&~?f&~?o&~?t&~?r&))
(combination (letter U)(number ?u&~?f&~?o&~?t&~?w&~?r&: (= (+ ?w ?w)
?u)))

=>
(printout t "Solutia este : " crlf)
(printout t " T = " ?t)
(printout t " W = " ?w)
(printout t " O = " ?o)
(printout t " F = " ?f)
(printout t " U = " ?u)
(printout t " R = " ?r)

(printout t crlf)
(printout t " " ?t ?w ?o crlf)
(printout t " + " ?t ?w ?o crlf)
(printout t " " "-----" crlf)
(printout t " = " ?f ?o ?u ?r crlf)

)
(run)
(reset)
Pb4:

(deftemplate combination (slot color (type STRING))(slot country (type


STRING)))

(defrule populate

=>
(assert (color red)
(color blue)
(color yellow)
(color green)
(country Ukraina)
(country Moldova)
(country Bulgaria)
(country Romania)
(country Ungaria)
(country Serbia)
))

(defrule generate-combinations
(color ?c)
(country ?a)
=>
(assert (combination (country ?a)(color ?c))))

(defrule solutie
(combination (country Romania)(color ?RO&: (= red ?RO)))
(combination (country Moldova)(color ?MD&~?RO&))
(combination (country Bulgaria)(color ?BG&~?RO&))
(combination (country Ukraina)(color ?UA&~?MD&~?RO&))
(combination (country Ungaria)(color ?UN&~?RO&~?UA&))
(combination (country Serbia)(color ?SE&~?UN&~?RO&~?BG&))

=>
(printout t " O solutie este : " crlf)
(printout t " Romania = " ?RO)
(printout t " Moldova = " ?MD)
(printout t " Bulgaria = " ?BG)
(printout t " Ukraina = " ?UA)
(printout t " Ungaria = " ?UN)
(printout t " Serbia = " ?SE crlf)

(reset)
(run)

You might also like