Selasa, 08 April 2008

Define the Puzzled

Good morning,

About the logical deduction of the Einstein Quiz I've said before, I got the inspiration from the a program called PROLOG (Which I learned it when I got the AI course from my undergraduate College, but I forget what is it's stands to :)) , which can make an answer given some facts & some rule, but it seems like when I try to give input of Einstein Quiz to Prolog, I don't now how to do it because it is so complicated. So I try to create a computer program that can do the deduction for this Quiz only. Maybe after I successfully developed the program, it can be solved to other Quiz maybe (only in my dream ... hahaha ..:) ) But it's still under the development ...

Before I develop the program, I wrote some logical deduction in a textfile, using logical syntax.
I started to develop the program from year 2002, but because of the business (it's busi-ness : kesibukan in Bahasa) as a programmer analyst, the project was suspended sometimes. At first, I developed the program using Visual Basic 6.0, but to continue follow the fastness changes of technology, currently I'm using Visual Basic .NET 2005 (but still out of date to now .. compared to the new Visual Basic .NET 2008 that just released lately :( )

So let's start to create a list of logical statements, from the Quiz statements.

The Brit lives in a red house.
The Swede keeps dogs as pets.
The Dane drinks tea.
The Norwegian lives in the first house.
The German smokes Prince.

The 5 statements above are facts (I called so) so we can write :


Note :
HouseColor(Brit,Red) is read in Englist : Brit has (a) house color of Red
Pet(Swede,Dogs) is read : Swede has pets of dogs, etc

The other statements is :

The green house is on the left of the white house.
The green house owner drinks coffee.
The person who smokes Pall Mall rears birds.
The owner of the yellow house smokes Dunhill.
The man living in the house right in the centre drinks milk.
The man who smokes Blend lives next to the one who keeps cats.
The man who keeps horses lives next to the man who smokes Dunhill.
The owner who smokes Blue Master drinks beer.
The Norwegian lives next to the blue house.
The man who smokes Blend has a neighbor who drinks water.

The 10 statements above I called "Rule" (maybe someone can give a better term to me)
and can be written as :

HouseColor(x,Green) ^ HouseColor(y,White) -> LeftSide(x,y)
HouseColor(x,Green) -> Beverage(x,Coffee)
Cigar(x,PallMall) -> Pet(x,Bird)
HouseColor(x,Yellow) -> Cigar(x,Dunhill)
Position(x,3) -> Beverage(x,Milk)
Cigar(x,BlueMaster) -> Beverage(x,Beer)
Cigar(x,Blend) ^ Pet(y,Cat) -> LivesNext(x,y)
Pet(x,Horse) ^ Cigar(y,Dunhill) -> LivesNext(x,y)
HouseColor(x,Blue) -> LivesNext(x,Norwegian)
Cigar(x,Blend) ^ Beverage(y,Water) -> LivesNext(x,y)

Note :
^ = AND logical operator
v = OR logical operator
-> = Conclude

About the statement :

The man living in the house right in the centre drinks milk.
Because there is 5 persons live in the neighborhood, so the center must be in position 3
(It's kinda cheating because I don't write it "as is", but it's helping to solve the problem :p)
So : Position(x,3) -> Beverage(x,Milk)

After that, we create (actually, it's not create, but "define") additional rules & facts :

Rules :
LivesNext(x,y) -> LeftSide(x,y) v RightSide(x,y)
LeftSide(x,y) -> Position(x,v) ^ Position(y,z) ^ LessOne(v,z)
RightSide(x,y) -> Position(x,v) ^ Position(y,z) ^ LessOne(z,v)

Facts :

Note :
LessOne(1,2) is read : 1 is less one of 2 because the difference of 2 to 1 (2-1) is one, right ?
The facts above I added because I want to make an position order from one house to the other

That' all folks! I will continue this in other time. Thanks for reading! And see you later ... :)

Tidak ada komentar: