22.1 Introduction: Question

Exercise: Introduction


In this series of exercises, we shall solve a murder mystery by writing a Prolog program.

You can either choose to face the challenge head-on and just start solving it. Alternatively, you can go through this series of exercises, which help you solve the problem in small, incremental steps. The exercises guide you through writing the Prolog program by giving hints and instructions. Each exercise will, once answered, solve part of the problem.

But first the mystery itself.

A Murder Mystery

Sunday morning at the shared flat 'House of Dawn': Sherlock Holmes has been summoned to solve a murder mystery. These are the facts of the case: Anna has been murdered with a club-like instrument. The time of death is assessed to have occurred Thursday or Friday. Nothing indicates more than one perpetrator. Indications are that the motive of the crime is money, jealousy, or insanity, and that the murderer should be found among the people sharing the flat. Sherlock Holmes has established that the murder weapon is either the wooden leg that was stolen from the penniless Ben either Thursday in Odensee or Wednesday in Copenhagen; or the hammer that was stolen from the toolbox in the flat Wednesday or Thursday. The murderer has entered Anna's room using a key that was stolen from Anna either Monday in Copenhagen or Tuesday in Odensee. A considerable amount of cash has also been removed from Anna's room. Anna's poor friend Beth has a copy of the key. Anna has a relationship to Ben, who in turn had a relationship with the rich girl Karen. Furthermore, Anna had a relationship to Peter, who is poor, but had a relationship to the wealthy girl Hannah, who in turn had a relationship to the equally wealthy Harry. Harry had been romantically involved with the poor girl Marie, who used to be involved with Adrian, who is wealthy, and used to be involved with the wealthy girl Karen. Peter was in Copenhagen on Monday and Tuesday, in Odensee Wednesday, in Copenhagen again Thursday, and had thereafter returned to the flat. Karen was in Odensee Monday through Wednesday, in Copenhagen Thursday and at the flat Friday. Harry had been at the flat on Monday, in Odensee on Tuesday, and had then returned again to the flat. Beth had spent her Monday at the flat, been in Odensee Tuesday and Wednesday, in Copenhagen on Thursday, and had returned to her home Friday morning. Adrian was in Copenhagen Wednesday, and at home for the rest of the week. Hannah was in Odensee Tuesday and Wednesday, at the flat Monday, Thursday, and Friday. Ben was in Copenhagen Monday and Tuesday, in Odensee Wednesday, in Copenhagen again on Thursday, and at home Friday. Marie had been in Copenhagen from Tuesday to Thursday, and at the flat Monday and Friday. Adrian and Marie have both been seeing a therapist because of psychotic disorders that occasionally are manifested as unmotivated violent behaviour.

The task is: Write a PROLOG program that assists Sherlock Holmes in finding the murderer!

If you want to, you can start solving the problem without going through this series of exercises. However, you may also follow these smaller steps, which break down the problem for you.

We suggest you print out this page so that you can refer to it while writing the program.

If you want no help in solving the problem, don't read on.

The overall idea

The overall idea is to codify all of the information given above in Prolog clauses. The idea is that the murderer must be someone who:

  • Had a motive. The motive could be either:
    • insanity,
    • money, or
    • jealousy.
  • Had access to perpetrating the crime. This involves both:
    • Having access to the weapon,
    • Having access to the key to the room, and
    • Being in the flat at the time of the crime.

The first exercise is to write a Prolog program-fragment which says the following:

A person X has access to committing the crime if that person has access to the key, access to the weapon, and access to committing the crime.

Write this in one Prolog clause using the predicates 'weapon_access(X)', 'key_access(X)' and 'crime_access(X)'. Do not worry right now about how these three predicates are to be implemented; we'll deal with that later. For now, simply assume that they exist and that they work.

Be sure to press the 'New document' button before starting to write, especially if you have just started the Prolog+CG system. (See this page for an explanation of the reason.)


Click to see an answer.

Prev: 22 A Murder Mystery
Up: 22 A Murder Mystery
Next: Weapon access