This puzzle can be solved using forward chaining, i.e., by using Drools or any similar RBS, but it isn&#39;t possible by implementing the givens as rules, expecting that an increase in the filled-in values will result in a (the) solution. Certainly, it is possible to write a rule such as<br>
<br>rule EnglishRed<br>when<br>&nbsp;&nbsp;&nbsp; $h: House( nationality == null &amp;&amp; colour == Colour.RED ||<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nationality == Nationality.ENGLISHMAN &amp;&amp; colour == null )<br>then<br>&nbsp;&nbsp;&nbsp; modify( $h ){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setNationality( Nationality.ENGLISHMAN ),<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setColour( Colour.RED )<br>&nbsp;&nbsp;&nbsp; }<br>end<br><br>which adds &quot;red&quot; or &quot;Englishman&quot; to a House as soon as the other property is present. But this approach comes to a standstill as soon as more sophisticated mental processes are required in the manual solution technique.<br>
<br>One approach I&#39;ve tried successfully is to generate all permutations of animals, colours, drinks, nationalities and smokes (120 each), insert them as facts, and to write one big rule according to the givens. A similar approach uses facts consisting of an attribute indication (animal,... smoke), a value and a reference to a House, again starting with all possible associations and using one rule to select the attribute combinations satisfying the givens.<br>
<br>I&#39;m not quite sure how the rules presented by Miles should work, but I don&#39;t think that swapping values between House facts is going to work, even when more defensive strategies against looping are employed.<br>
<br>-W<br><br><br><br><br><br><br><br><div class="gmail_quote">On 15 June 2011 14:47, FrankVhh <span dir="ltr">&lt;<a href="mailto:frank.vanhoenshoven@agserv.eu">frank.vanhoenshoven@agserv.eu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br>
<br>
This is a puzzling one... but then again, I believe that is the idea.<br>
<br>
I should have a very close look at it, but a loop always suggests that there<br>
are rules that re-activate themselves or eachother.<br>
<br>
For example:<br>
<div class="im"><br>
rule &quot;抽kools牌的香烟的人与养马的人是邻居&quot;<br>
 &nbsp; &nbsp;when<br>
 &nbsp; &nbsp; &nbsp; &nbsp;$h1:House(cigarette == Cigarette.kools)<br>
 &nbsp; &nbsp; &nbsp; &nbsp;$h2:House(pet == Pet.horse)<br>
 &nbsp; &nbsp; &nbsp; &nbsp;$h3:House(eval(position - $h2.position == 1) || eval(position -<br>
$h2.position == -1))<br>
 &nbsp; &nbsp; &nbsp; &nbsp;eval($h1.position - $h2.position != 1 &amp;&amp; $h1.position - $h2.position<br>
!= -1)<br>
 &nbsp; &nbsp;then<br>
 &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(&quot;抽kools牌的香烟的人与养马(horse)的人是邻居&quot;);<br>
 &nbsp; &nbsp; &nbsp; &nbsp;modify($h1){setCigarette($h3.cigarette)};<br>
 &nbsp; &nbsp; &nbsp; &nbsp;modify($h3){setCigarette(Cigarette.kools)};<br>
end<br>
<br>
</div>In this rule, $h3 and $h1 might be the same house OR $h1 and $h2 might be<br>
the same house. I think you need to add extra constraints to make sure that<br>
all 3 houses are different.<br>
<br>
But still, I haven&#39;t had a thorough look at all the rules neither did I<br>
refresh my knowledge of the zebrapuzzle, so I am not sure whether this is a<br>
complete answer (if any).<br>
<br>
Please let us know.<br>
<br>
Regards,<br>
Frank<br>
<font color="#888888"><br>
<br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/rules-users-Can-I-solve-the-Zebra-Puzzle-in-drools-tp3066485p3067138.html" target="_blank">http://drools.46999.n3.nabble.com/rules-users-Can-I-solve-the-Zebra-Puzzle-in-drools-tp3066485p3067138.html</a><br>

Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</font></blockquote></div><br>