Question: Please help!!! I. Introduction Prolog is a language that is suitable for solving problems in the field of artificial intelligence. That is, it can be
Please help!!!
I. Introduction 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 used to be solvable only by human brains. In this assignment, you are asked to write a Prolog program to solve a logic puzzle. II. Using Prolog Gnu Prolog has been installed on the VM. To use it, just issue the prolog command from a terminal. To simplify the loading of programs, you should start the command from the folder where you saved your program. If you prefer to use prolog on your native computing environment, Gnu Prolog can be downloaded from http://www.gprolog.org. To load your program into prolog, you can use the consult command, as in the following example: | ?- consult('myProgram.pl'). If you are using the Microsoft Windows version, you can also use the File | Consult menu selection to load the file from a chooser. III. The Puzzle I was at a park trying to come up with material for my stand-up-comedy routine when I heard a group of kids laughing hysterically. These kids were cracking each other up with some pretty goofy jokes, so for inspiration, I asked the four children for their funniest bits. Each child (no two of whom are the same age) told me a different knock-knock joke (including one about an interrupting cow) and a different amusing anecdote (one told a story about his or her little brother). Each child also did a different funny impression (one child imitated SpongeBob SquarePants). While I couldnt use any of the kids material in my act, it was a pleasure to laugh at jokes that werent my own! From the information provided, determine the age (6 through 9 years old) of each child and the impression each kid performed, as well as the knock-knock joke and funny story he or she told me. 1. The kid who told the bananas-and-oranges knock-knock joke is older than Nate. 2. Nate is older than the child who did an impression of his or her teacher 3. The child who did an impression of his or her teacher didnt tell me a funny story about a recent family vacation. 4. The kid who told the Sam-and-Janet knock-knock joke isnt the one who did an impression of a moose. 5. The kid who told the Sam-and-Janet knock-knock joke isnt the youngest child. 6. Hillary did an impression of an airplane. 7. Hillary is neither the kid who told me the hilarious story about a family vacation nor the one who related the story about an incident on a jungle gym. Spring 2017 Fayetteville State University Albert Chan CSC322 Assignment 5 Programming Languages Page 2 of 3 8. The kid who told the little-old-lady knock-knock joke is older than Vanessa. 9. Vanessa is older than the child who told the Sam-and-Janet knock-knock joke. 10. The kid who told me a story about a petting zoo is one year older than Foster. IV. Analysis Lets first do some book-keeping work, there are: 4 children: Foster, Hillary, Nate, and Vanessa; 4 ages: 6, 7, 8, and 9 years old; 4 impressions: airplane, moose, SpongeBob SquarePants, and teacher; 4 jokes: bananas and oranges, interrupting cow, little old lady, and Sam and Janet; and 4 stories: family vacation, jungle gym, little brother, and petting zoo. Now lets define a data structure to hold the information about the superheroes. There are many ways to do this. The following is only one of the many possibilities: /* child(age,name,impression,joke,story). */ Note that you only have to keep this structure in mind. You do not have to actually enter it into your Prolog program. That is why we put it here as a comment (Prolog comments are enclosed in /* and */, you can also use the single line comments which start with triple percentage sign %%% and extend until the end of the line). Next we define a childList that contains the five children (note that the underscore character _ by itself is used to represent the dont care or dont know values in Prolog): childList([child(6,_,_,_,_),child(7,_,_,_,_), child(8,_,_,_,_),child(9,_,_,_,_)]). Now we can encode the hints into the solution (Rule 1 is encoded below for you): solution(S) :- childList(S), member(child(B,_,_,bananas-and-oranges,_), S), member(child(N,nate,_,_,_), S), B > N, . The first line says that S is a solution only if S is a childList. The comma at the end of the line means the rule is not completed yet. It still has other conditions to satisfy. These additional conditions are specified in the subsequent lines. The second line assumes the age of the child told the bananas and orange knock-knock joke is B; and the third line assumes Nates age is N, then from Rule 1, we know that B > N. The last condition in the rule should end with a period. Also note that in Prolog, names start with a lowercase letter are literals (constants), while names start with an uppercase letter are variables. Spring 2017 Fayetteville State University Albert Chan CSC322 Assignment 5 Programming Languages Page 3 of 3 Once your program is loaded into Prolog, simply issuing the following command should give you the answer (Hint: There is exactly one solution to this puzzle): solution(S).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
