Daftar Blog Saya

Selasa, 15 Desember 2009

FP 3

soal1
soal2
how to solve it :
First, write the code number 1 given in the problem into notepad (or just copy paste) and then save it in extension “.pl”, the name of the file is up 2 u all. Ex: FP3.pl
database 1
And so does the number 2
database 2_2
(I save it with the name “FP3_2.pl”)
Open your prolog program and consult  the FP3.pl
consult
consult2
Or just click it twice on the file FP3.pl
Now, let’s discuss number 1 first. After the database has been loaded, things we should do next is to solve this problems : find : (a) all the mammals, (b) all the carnivores that are mammals, (c) all the mammals with stripes, (d) whether there is a reptile that has a mane.
How do we solve it then? That’s easy, I’ll tell you then.
For the first problem, the way to find all the mammals is by typing this into your prolog program : “animal(mammal,X,_,_).” (I replace the third and the fourth with “_” because we won’t be needing that element) and press enter. This the first result:
1a_1
the first output will be tiger. To show the another result just press “;”  (“;” means “or” in prolog) and press it again until the output is “no”.
And the result will be like this :
1a
That’s it.
Now for the second problem. Type this into your prolog : “animal(mammal,X,carnivore,_).” (this time I replace the third element with carnivore because it will be used to find all the carnivores). And do the same steps as the first problem. The result will be like this
1b
The same goes to the third problem. Type this into your prolog “animal(mammal,X,_,stripes).” (I assume this time you will understand why I type it like that)  And follow the previous steps. The result will be like this
1c
For the fourth problem. It will be the same as the previous by typing this “animal(mammal,X,_,mane).”. But when you press “;” the result will be “no”. Why? Because there is only one animal that’s mammal and has a mane.
1d
And it’s done
Time to discuss number 2. To solve the number 2, edit number 2’s code and add this rule “couple(X,Y):-person(X,male),person(Y,female).”
database 2
save it. After that load it into your prolog program.
Type “couple(X,Y).” and press enter. The first result will be
X = bill
Y = carol
To show the another result keep pressing “;” until the output is “ no”. and this is the result :
2
Actually it is the same like combinatorial, just like the final project week 2. Ok, that’s it for now. See ya next time. And greatest thanks to Mr. AM………

Tidak ada komentar:

Posting Komentar