Public Zone 公開區 > General Topics 綜合題目

Felix's puzzle

<< < (2/3) > >>

chin:
I think the following is wrong, it should be "mother_child(boymom, girlmom)" instead.


--- Quote ---mother_child(girlmom,boymom).
--- End quote ---

kido:

--- Quote from: chin on 16 April 2011, 16:49:41 ---I think the following is wrong, it should be "mother_child(boymom, girlmom)" instead.


--- End quote ---

Thanks.... It really depends on how you interpret the 【8樓】


--- Quote ---【8樓】女孩母親見到男友母親:"媽"

--- End quote ---

Is that "媽" said by girlmom, or boymom ??? It wasn't clear.

Anyway, I tried to do what you said:


--- Quote ---mother_child(boymom, girlmom).

--- End quote ---

And result ???


--- Quote ---1 ?- related(girldad, boymom).

No

--- End quote ---

The system isn't able to solve it.... May need more relation to teach it... oh.

kido:
Redo with new relation added "mate"...To save time, here is my whole program. '%%' is comment.



--- Quote ---parent_child(X,Y) :- father_child(X,Y).
parent_child(X,Y) :- mother_child(X,Y).
sibling(X, Y) :- parent_child(Z, X), parent_child(Z, Y), X\=Y.
mate(X,Y) :- father_child(X,Z), mother_child(Y,Z).
mate(X,Y) :- mother_child(X,Z), father_child(Y,Z).


%%
%% Facts
%%

%% 2樓
mother_child(girlmom,girl).

%% 3樓
father_child(boy,girl).

%% 4樓
%%mother_child(girl, xxx).
%%father_child(boy, xxx).

%% 5樓
father_child(girldad,boy).
mother_child(boymom,boy).

%% 6樓
%% mate(boymom,girldad).

%% 7樓
sibling(boydad,girldad).

%% 8樓
%%mother_child(girlmom,boymom).
mother_child(boymom,girlmom).

%% 9樓
father_child(boydad,girlmom).



related(X,X).
related(X,Y) :- mate(X,Z), related(Z,Y), write(X), write(' is mate of '), write(Z), nl.
related(X,Y) :- father_child(X,Z), related(Z,Y), write(X), write(' is father of '), write(Z), nl.
related(X,Y) :- mother_child(X,Z), related(Z,Y), write(X), write(' is mother of '), write(Z), nl.
related(X,Y) :- sibling(X,Z), related(Z,Y), write(X), write(' is sibling of '), write(Z), nl.


--- End quote ---

Note:

(1) I added a new relation called 'mate'. 2 people are mate, if they produce an offspring and one of them is father, and the other is mother, or vice versa.

(2) anything with 'xxx' is removed. It's not relevant in this case.

(3) Adopted chin's view on relation between girlmom and boymom.

(4) I rearrange the order of 'related' so that it won't have 'run out of stack' problem.


Now run it......


--- Quote ---2 ?- related(girldad,boymom).
girldad is mate of boymom

Yes

--- End quote ---

So, a simple relationship is that they're mate with offspring boy

chin:

--- Quote from: kido on 16 April 2011, 17:11:27 ---Thanks.... It really depends on how you interpret the 【8樓】

Is that "媽" said by girlmom, or boymom ??? It wasn't clear.

Anyway, I tried to do what you said:

And result ???

The system isn't able to solve it.... May need more relation to teach it... oh.

--- End quote ---

I read this as the girl's mom calling the boy's mom "Mom".

Besides how the words were arrange, you can sort of guess that the guy is 40, the girl is 20, the girlmom is ~40, so the boymom should be around ~60.

kido:

--- Quote from: chin on 17 April 2011, 02:18:39 ---I read this as the girl's mom calling the boy's mom "Mom".

Besides how the words were arrange, you can sort of guess that the guy is 40, the girl is 20, the girlmom is ~40, so the boymom should be around ~60.

--- End quote ---

No, I didn't think about this..... :)

And after I figured out that boymom and girldad had a 'mate' relation.... I knew I mis-understood 6樓 that they're 'mated'.... It should be a relation I should discover rather than provided.


--- Quote ---%% 6樓
%% mate(boymom,girldad).

--- End quote ---

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version