Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>without using CLP(FD), you should used combinatorial ability of Prolog expressing the problem and the constraints in appropriate way. For instance</p> <pre><code>puzzle(Name) :- L = [[mason, Pos1, Blond1, Handsome1, UnScared1], [alex, Pos2, Blond2, Handsome2, UnScared2], [steve, Pos3, Blond3, Handsome3, UnScared3], [simon, Pos4, Blond4, Handsome4, UnScared4] ], permutation([1,2,3,4], [Pos1,Pos2,Pos3,Pos4]), maplist(yn, [Blond1, Handsome1, UnScared1, Blond2, Handsome2, UnScared2, Blond3, Handsome3, UnScared3, Blond4, Handsome4, UnScared4 ]), ... </code></pre> <p>Each variable (those symbols starting Uppercase!) is an attribute of a person, and can assume a value from the domain. yn/1 it's a service fact, allows those binary values to assume either yes or no:</p> <pre><code>yn(y). yn(n). </code></pre> <p>The constraints can then be expressed in this way (just the first here)</p> <pre><code>... % Two of them who are not blond are standing on either side of Mason. member([mason, I1, _,_,_], L), member([_, I2, n,_,_], L), member([_, I3, n,_,_], L), (I2&gt;I1, I3&gt;I1 ; I2&lt;I1, I3&lt;I1), ... </code></pre> <p>and the solution will be</p> <pre><code> % One of them is blond, handsome, and unscarred. member([Name, _, y, y, y], L). </code></pre> <p>I'm not sure I understand every constraint (in English), indeed my program doesn't find a solution.</p> <p>The program is rather slow, and calls for CLP(FD). Edit your question (add appropriate tag, for instance), if you are interested in a CLP(FD) solution.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload