Note that there are some explanatory texts on larger screens.

plurals
  1. POProlog - Rules are correct, but not outputting the way it's supposed to?
    primarykey
    data
    text
    <p><strong>Clue</strong></p> <p>Four guests (Colonel Mustard, Professor Plum, Miss Scarlett, Ms. Green) attend a dinner party at the home of Mr. Boddy. Suddenly, the lights go out! When they come back, Mr Boddy lies dead in the middle of the table. Everyone is a suspect. Upon further examination, the following facts come to light:</p> <ul> <li>Mr Boddy was having an affair with Ms. Green.</li> <li>Professor Plum is married to Ms. Green.</li> <li>Mr. Boddy was very rich.</li> <li>Colonel Mustard is very greedy.</li> <li>Miss Scarlett was also having an affair with Mr. Boddy.</li> </ul> <p>There are two possible motives for the murder: </p> <ul> <li>Hatred: Someone hates someone else if that other person is having an affair with his/her spouse.</li> <li>Greed: Someone is willing to commit murder if they are greedy and not rich, and the victim is rich.</li> </ul> <p>Part A: Write the above facts and rules in your Prolog program. Use the following names for the people: colMustard, profPlum, missScarlet, msGreen, mrBoddy. Be careful about how you encode (or don’t encode) symmetric relationships like marriage - you don’t want infinite loops! <code>married(X,Y) :- married(Y,X) % INFINITE LOOP</code></p> <pre><code>?-suspect(Killer,mrBoddy) Killer = suspect_name_1 Killer = suspect_name_2 etc. </code></pre> <p>Part B: Write a predicate, suspect/2, that determines who the suspects may be, i.e. who had a motive.</p> <pre><code>?-suspect(Killer,mrBoddy) Killer = unique_suspect. </code></pre> <p>Part C: Add a single factto your database that will result in there being a unique suspect. Clearly indicate this line in your source comments so that it can be removed/added for grading.</p> <pre><code>?-suspect(Killer,mrBoddy) Killer = unique_suspect. </code></pre> <hr> <p>Whenever I type in </p> <pre><code>suspect(Killer,mrBoddy). </code></pre> <p>I get </p> <pre><code>suspect(Killer,mrBoddy). Killer = profPlum </code></pre> <p>I'm missing </p> <pre><code>Killer = colMustard. </code></pre> <p>Here's my source.</p> <pre><code>%8) Clue %facts affair(mrBoddy,msGreen). affair(missScarlett, mrBoddy). affair(X,Y) :- affair(X,Y), affair(Y,X). married(profPlum, msGreen). married(X,Y) :- married(X,Y), married(Y,X). rich(mrBoddy). greedy(colMustard). %rules hate(X,Y) :- married(X,Spouse), affair(Y,Spouse). greed(X,Y) :- greedy(X), not(rich(X)), rich(Y). %suspect suspect(X,Y):- hate(X,Y). suspect(X,Y):- greed(X,Y). </code></pre>
    singulars
    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.
 

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