Question: Prolog is a language that is suitable for solving problems in the field of artificial intelligence; that is , it can be used to solve

Prolog is a language that is suitable for solving problems in the field of artificial intelligence; that is, it can be used to solve problems that once were solvable only by human brains. In this assignment, you are asked to write a Prolog program to solve logic puzzle.
To load your program into Prolog, you can use the consult command, as in the following example: |?- consult('myProgram.pl').Gnu Prolog on Microsoft Windows, use "File | Consult..."
The Puzzle (Adopted from Original Logic Problems published by PennyPress some years ago)
In order to mooch some air conditioning. Jack braved the heat wave and came out to the Jefferson Decaplex. Taking a quick glance at the marquee, he can see that a different movie is playing on each screen (1 through 10) and that each film is a different genre (one is a spy thriller). Looking at all these choices, He feels like he is being given some kind of screen test! From the information provided, can you determine the genre of the
movie playing on each screen?
1. The screen on which Brisbane is playing is numbered exactly 1 higher than the screen on which the historical epic is showing but exactly 1 lower than the screen on which Long Shot is playing.
2. Jet Set is playing on a higher-numbered screen than Pigeon but a lower-numbered screen than the Western.
3. The musical is playing on screen 4.
4. The screen on which the comedy is playing is numbered exactly1 higher than the screen on which The Gentleman is showing but exactly 1 lower than the screen on which Frostfire is playing.
5. The Gentleman is not a science-fiction movie.
6. The horror movie is playing on the screen numbered exactly 1higher than the screen on which Newtons Laws is showing.
7. Vulture Gulch is playing on the screen numbered exactly 1 higher than the screen on which the documentary is showing.
8. The documentary is playing on a higher-numbered screen than the comedy.
9. The screen on which Ellipsis is playing is numbered exactly 1higher than the screen on which the action flick is showing but exactly 1 lower than the screen on which the science-fiction movie is playing.
10. The action film, the historical epic, and the romance movie are playing on screens 1,2, and 3, in some order; one of these films is Tower of London.
11.The difference between the numbers of the screen on which Newtons Laws and Vulture Gulch are playing is the same as the difference between the numbers of screen on which the Gentleman and Tower of London are showing.
Analysis
There are:
10 screens: 1 through 10;
10 movie titles: Brisbane, Ellipsis, Frostfire, Jet Set, Long Shot, Pigeon, Newtons Laws, The Gentleman, Tower of London, and Vulture Gulch;
10 genres: action flick, comedy, documentary, historical epic, horror, musical, romance, spy thriller, science fiction, and western.
Now lets define a data structure. The following is only one of the many possibilities: /* screen(screen_number, movie_title, genre).*/
Note that you only have to keep this structure in mind. You do not have to enter it into your Prolog program. That is why we put it here as a comment (Prolog has two types of comments: multiline comments are enclosed in /* and */, you can also use single line comments which start with triple percentage sign %%%
and extend until the end of the line).Next, we define an arrangement that contains the ten screens (note that the underscore character _ by itself is used to represent a dont care or dont know value in Prolog):
arrangement([screen(1,_,_), screen(2,_,_), screen(3,_,_), screen(4,_,_),
screen(5,_,_), screen(6,_,_), screen(7,_,_), screen(8,_,_), screen(9,_,_), screen(10,_,_)]).
In our program, we will need to use variables to represent different screens. We will use the following system of variables:
We use the variables Brisbane, Ellipsis, Frostfire, Jet_Set, Long_Shot, Pigeon, Newton_s_Laws, Gentleman, Tower_of_London, and Vulture_Gulch to represent the screen number on which the movie Brisbane, Ellipsis, Frostfire, Jet Set, Long Shot, Pigeon, Newtons Laws, The Gentleman, Tower of London, and Vulture Gulch is playing, respectively.
We use the variables Action, Comedy, Documentary, Historical, Horror, Musical, Romance, Spy, SciFi, and Western to represent the screen on which action flick, comedy, documentary, historical epic, horror, musical, romance, spy thriller, science fiction, and western movie is playing, respectively.
To define solution and encode variables:
solution(S) :- arrangement(S),
member(screen(Brisbane,brisbane,_), S),
...
member(screen(Action,_,action), S),
....
The first line says that S is a solution if S is an arrangement. The comma at the end of the line means the rule is not complete yet. It still has other conditions to satisfy. These additional conditions are specified in the subsequent lines. The other 2 groups of lines establish variable and fact relationships.
Prolog is a language that is suitable for solving

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!