chinman.com

Public Zone 公開區 => General Topics 綜合題目 => Topic started by: chin on 14 April 2011, 23:12:49

Title: Felix's puzzle
Post by: chin on 14 April 2011, 23:12:49
I am trying to work out the relationships...

轉貼
【1樓】某兩會委員發言:“上海是全世界的上海,上海的房價應該和國際接軌。我覺得80後男孩子如果買不起房子,80後女孩子可以嫁給40歲的男人。 80後的男人如果有條件了,到40歲再娶20歲的女孩子也是不錯的選擇。”
【2樓】回复: 我終於到40歲了,找到一個年輕貌美的20歲女友去她家見家長。開門的是當年讀大學時相處了幾年的初戀女友新女友喊了一聲:媽~
【3樓】補充:她媽看到我,驚得倒吸一口冷氣。沒等我反應過來,然後把女兒拉進房間裡,對女兒說“你不能和他在一起,他是你親生父親啊!”
【4樓】繼續補充: 女兒:我已經有了他的骨肉……
【5樓】 這時女孩的60多歲的父親走出來看見了女孩的男友,小聲的對他說:“你怎麼來了,給你媽和你的生活費不是每月都按時打去的?
【6樓】這時"叮咚",女孩男友的媽來見親家,見到女孩的父親:"怎麼是你"
【7樓】女孩男友的父親停完車也上樓了,一見女孩的父親馬上淚流滿面:"你不就是我失散多年的弟弟?"
【8樓】女孩母親見到男友母親:"媽"
【9樓】女孩母親見到男友他爸,叫了一聲“爹!”,立刻暈厥過去
請問—— 1、你能理解到幾樓? 2、男友他媽的媽見到女友他媽的爸叫什麼?
Title: Re: Felix's puzzle
Post by: chin on 14 April 2011, 23:37:14
Let's have standard notations first...

B = the guy in question
G = the girl in question, and the current girlfriend of B

P(x) is bio paternal relationship, M(x) is bio maternal relationship, P+M(x) means the confirmed bio parents of x.
P'(x) & M'(x) denotes paternal or maternal relationship by marriage, although may nmot biologically

So here is my try

2. M(G) = early girlfriend of B
3. B = P(G)
4. B + G = P+M(?)
5. P'(G) = P(B)
6. just confirms 5
7. P'(B) = brother of P'(G)
8. M(B) = M(M(G))
9. P(B) = P(M(G))

Conclusion
- M(G) is sister of B, G is the offspring of brother & sister B + M(G) (G)!

女友他媽的爸 is the son in law of 男友他媽的媽
Title: Re: Felix's puzzle
Post by: kido on 14 April 2011, 23:55:24
他媽的男友真是他媽的… ??? ???
Title: Re: Felix's puzzle
Post by: kido on 15 April 2011, 22:51:30
Let's have standard notations first...

B = the guy in question
G = the girl in question, and the current girlfriend of B

P(x) is bio paternal relationship, M(x) is bio maternal relationship, P+M(x) means the confirmed bio

...



Chin, your method reminded me my long forgotten computer language called 'Prolog', which is very suitable for this kind of problem.....and I'm going to illustrate my trial here  ;D  These are predicate logic which is mentioned in this  (http://chinman.com/index.php/topic,230.msg3025.html#msg3025)thread.

First, I needed to tell the system some basic rules:

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.

(1) and (2) rules tell a parent_child relation is either  it's a father_child relation or mother_child relation.
(3) rule tells a sibling relation between 2 is they share a common parent and they're not the same!!! Simple...

Now I'm going to tell the system the relation of these guys....

Quote
mother_child(girlmom,girl).

gf_of(girlmom,boy).

father_child(boy,girl).

father_child(girldad,boy).

sibling(boydad,girldad).

mother_child(girlmom,boymom).

father_child(boydad,girlmom).

I hope I'm getting the above correct... To explain:
Rule (1) tells girlmom is mother of girl.
Rule (2) tells girlmom is girlfriend of boy.
etc.

Now I added in Prolog environment to see whether they're related, if you're familiar with recursion, it should be easy to understand below Rule (1), which says anything should related to himself. Others should be similar.

Quote
related(X,X).
related(X,Y) :- father_child(X,Z), related(Z,Y).
related(X,Y) :- mother_child(X,Z), related(Z,Y).
related(X,Y) :- sibling(X,Z), related(Z,Y).

and I typed
Quote
? -  related(girldad,boymom).

Yes

Yes, they're related somehow....but how do I get their real relationship???

I further modified the related to
Quote
related(X,X).
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.

Now I really tried it again:

Quote
?- related(girldad,boymom).
girl is sibling of boymom
boy is father of girl
girldad is father of boy

If you read the above reversely, you read their relation, which implies 'girldad' is grand-dad of boymom ????  I really don't know.

But I got the fun already!!!!  :D :D :D :D
Title: Re: Felix's puzzle
Post by: chin on 16 April 2011, 02:20:06
I am pretty drunk now after the dinner at the private kitchen....

I will try to understand the program flow when I am more "normal".
Title: Re: Felix's puzzle
Post by: chin on 16 April 2011, 16:49:41
I think the following is wrong, it should be "mother_child(boymom, girlmom)" instead.

Quote
mother_child(girlmom,boymom).
Title: Re: Felix's puzzle
Post by: kido on 16 April 2011, 17:11:27
I think the following is wrong, it should be "mother_child(boymom, girlmom)" instead.


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

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

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

Anyway, I tried to do what you said:

Quote
mother_child(boymom, girlmom).

And result ???

Quote
1 ?- related(girldad, boymom).

No

The system isn't able to solve it.... May need more relation to teach it... oh.
Title: Re: Felix's puzzle
Post by: kido on 17 April 2011, 01:53:33
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.


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

So, a simple relationship is that they're mate with offspring boy
Title: Re: Felix's puzzle
Post by: chin on 17 April 2011, 02:18:39
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.

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.
Title: Re: Felix's puzzle
Post by: kido on 17 April 2011, 02:24:36
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.

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).
Title: Re: Felix's puzzle
Post by: kido on 21 April 2011, 15:11:12
I have seen original question posted on other forum.... for completeness, here is my LAST attempt... which should solve this problem completely.... However, this is just kind of fun, don't take it seriously (ain't I?)  ;) ;)

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).

son(X,Y) :-   parent_child(Y,X).

%%
%% 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,Y, 'mate') :- mate(X,Y).
related(X,Y, 'parent') :- parent_child(X,Y).
related(X,Y, 'sibling') :- sibling(X,Y).
related(X,Y, 'son') :- son(X,Y).

path(A,B,Path) :-
       travel(A,B,[A],Path).

travel(A,B,P,[B|P]) :-
       related(A,B,R),
      write(R), nl.
travel(A,B,Visited,Path) :-
      related(A,C,R),  
       C \= B,
       \+member(C,Visited),
       travel(C,B,[C|Visited],Path),
      write(R), nl.

Notes:

(1) Further thro' in relation 'son' (in fact son or daughter)

(2) Revamped relation 'related' again.

(3) Now the 'path' predicate should find ALL possible relation instead of just finding ONE solution as done previously.

Now run it again:

Quote
1 ?- path(boymom,girldad,P).
mate
P = [girldad, boymom] ;

sibling
mate
P = [girldad, boydad, boymom] ;

son
mate
parent
mate
P = [girldad, boy, girlmom, boydad, boymom] ;

son
son
parent
parent
mate
P = [girldad, boy, girl, girlmom, boydad, boymom] ;

son
sibling
parent
mate
P = [girldad, boy, girlmom, boydad, boymom] ;

son
parent
P = [girldad, boy, boymom] ;

sibling
son
mate
parent
P = [girldad, boydad, girlmom, boy, boymom] ;

sibling
son
son
parent
parent
P = [girldad, boydad, girlmom, girl, boy, boymom] ;

sibling
son
sibling
parent
P = [girldad, boydad, girlmom, boy, boymom] ;

son
mate
parent
P = [girldad, boy, girlmom, boymom] ;

son
son
parent
parent
P = [girldad, boy, girl, girlmom, boymom] ;

son
sibling
parent
P = [girldad, boy, girlmom, boymom] ;

sibling
son
parent
P = [girldad, boydad, girlmom, boymom] ;

false.

The program shows that there are > 10 relations between them.... To name them.... I will leave to anyone who are interested.
Title: Re: Felix's puzzle
Post by: chin on 21 April 2011, 17:41:31
And the answer to the last question?
Title: Re: Felix's puzzle
Post by: kido on 21 April 2011, 18:28:11
Oh, yeah, I thought it was asking 男友他的媽見到女友的爸  instead of  男友他媽的媽見到女友他媽的爸, because "他媽的" is not part of the relation....

But anyway, now I throw in new relation :

And to makes things more complicated, now I put back the "xxx".

Quote
mother_child(boymm,boymom).
father_child(girlmd,girlmom).

And run it:

Quote
1 ?- path(boymm,girlmd,P).
mate
parent
P = [girlmd, boymom, boymm] ;

son
mate
parent
mate
parent
P = [girlmd, girlmom, boy, girldad, boymom, boymm] ;

son
son
mate
parent
mate
parent
P = [girlmd, girlmom, girl, boy, girldad, boymom, boymm] ;

son
son
parent
parent
mate
parent
P = [girlmd, girlmom, girl, boy, girldad, boymom, boymm] ;

son
son
sibling
parent
parent
mate
parent
P = [girlmd, girlmom, girl, xxx, boy, girldad, boymom, boymm] ;

son
son
son
parent
parent
mate
parent
P = [girlmd, girlmom, girl, xxx, boy, girldad, boymom, boymm] ;

son
sibling
parent
mate
parent
P = [girlmd, girlmom, boy, girldad, boymom, boymm] ;

son
parent
mate
parent
P = [girlmd, girlmom, boydad, boymom, boymm] ;

son
mate
parent
sibling
mate
parent
P = [girlmd, girlmom, boy, girldad, boydad, boymom, boymm] ;

son
son
mate
parent
sibling
mate
parent
P = [girlmd, girlmom, girl, boy, girldad, boydad, boymom, boymm] ;

son
son
parent
parent
sibling
mate
parent
P = [girlmd, girlmom, girl, boy, girldad, boydad, boymom, boymm] ;

son
son
sibling
parent
parent
sibling
mate
parent
P = [girlmd, girlmom, girl, xxx, boy, girldad, boydad, boymom, boymm] ;

son
son
son
parent
parent
sibling
mate
parent
P = [girlmd, girlmom, girl, xxx, boy, girldad, boydad, boymom, boymm] ;

son
sibling
parent
sibling
mate
parent
P = [girlmd, girlmom, boy, girldad, boydad, boymom, boymm] ;

son
mate
parent
parent
P = [girlmd, girlmom, boy, boymom, boymm] ;

son
son
mate
parent
parent
P = [girlmd, girlmom, girl, boy, boymom, boymm] ;

son
son
parent
parent
parent
P = [girlmd, girlmom, girl, boy, boymom, boymm] ;

son
son
sibling
parent
parent
parent
P = [girlmd, girlmom, girl, xxx, boy, boymom, boymm] ;

son
son
son
parent
parent
parent
P = [girlmd, girlmom, girl, xxx, boy, boymom, boymm] ;

son
sibling
parent
parent
P = [girlmd, girlmom, boy, boymom, boymm] ;

son
parent
parent
P = [girlmd, girlmom, boymom, boymm] ;

false.


Title: Re: Felix's puzzle
Post by: kido on 21 April 2011, 18:34:10
I think it's just for illustration, perhaps the only human-understandable relation is the one below:

Quote
1 ?- path(boymm,girlmd,P).
mate
parent
P = [girlmd, boymom, boymm] ;