Author Topic: Felix's puzzle  (Read 32040 times)

Offline chin

  • Global Moderator
  • *****
  • Posts: 6,663
Felix's puzzle
« 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、男友他媽的媽見到女友他媽的爸叫什麼?

Offline chin

  • Global Moderator
  • *****
  • Posts: 6,663
Re: Felix's puzzle
« Reply #1 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 男友他媽的媽

Offline kido

  • SBC Old Boys
  • ***
  • Posts: 310
Re: Felix's puzzle
« Reply #2 on: 14 April 2011, 23:55:24 »
他媽的男友真是他媽的… ??? ???
Hey, diddle, diddle ! The cat and the fiddle.

Offline kido

  • SBC Old Boys
  • ***
  • Posts: 310
Re: Felix's puzzle
« Reply #3 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 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
« Last Edit: 16 April 2011, 17:23:52 by kido »
Hey, diddle, diddle ! The cat and the fiddle.

Offline chin

  • Global Moderator
  • *****
  • Posts: 6,663
Re: Felix's puzzle
« Reply #4 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".

Offline chin

  • Global Moderator
  • *****
  • Posts: 6,663
Re: Felix's puzzle
« Reply #5 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).

Offline kido

  • SBC Old Boys
  • ***
  • Posts: 310
Re: Felix's puzzle
« Reply #6 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.
Hey, diddle, diddle ! The cat and the fiddle.

Offline kido

  • SBC Old Boys
  • ***
  • Posts: 310
Re: Felix's puzzle
« Reply #7 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
Hey, diddle, diddle ! The cat and the fiddle.

Offline chin

  • Global Moderator
  • *****
  • Posts: 6,663
Re: Felix's puzzle
« Reply #8 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.

Offline kido

  • SBC Old Boys
  • ***
  • Posts: 310
Re: Felix's puzzle
« Reply #9 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).
Hey, diddle, diddle ! The cat and the fiddle.