post on 26 Sep 2019 about 5038words require 17min
CC BY 4.0 (除特别声明或转载文章外)
如果这篇博客帮助到你,可以请我喝一杯咖啡~
If someone walked up to you and said, “Howdy, I’m your third cousin, twice removed,” would you have any idea what they meant? Most people have a good understanding of basic relationship words such as “mother,” “father,” “aunt,” “uncle,” “brother,” and “sister.” But what about the relationship terms that we don’t use in everyday speech? Terms like “second cousin” and “first cousin, once removed”? We don’t tend to speak about our relationships in such exact terms (“cousin” seems good enough when you are introducing one person to another), so most of us aren’t familiar with what these words mean.
Sometimes, especially when working on your family history, it’s handy to know how to describe your family relationships more exactly. The definitions below should help you out.
Your first cousins are the people in your family who have two of the same grandparents as you. In other words, they are the children of your aunts and uncles.
Your second cousins are the people in your family who have the same great-grandparents as you., but not the same grandparents.
Your third cousins have the same great great grandparents, fourth cousins have the same great-great-great-grandparents, and so on.
When the word “removed” is used to describe a relationship, it indicates that the two people are from different generations. You and your first cousins are in the same generation (two generations younger than your grandparents), so the word “removed” is not used to describe your relationship.
The words “once removed” mean that there is a difference of one generation. For example, your mother’s first cousin is your first cousin, once removed. This is because your mother’s first cousin is one generation younger than your grandparents and you are two generations younger than your grandparents. This one-generation difference equals “once removed.”
Twice removed means that there is a two-generation difference. You are two generations younger than a first cousin of your grandmother, so you and your grandmother’s first cousin are first cousins, twice removed.
Please fulfill the following tasks by using Prolog
:
mthCousinNremoved(X,Y,M,N)
. **Hint: You’d better define the predicate distance(X,Y,N)
by recursion.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
male(george).
male(kydd).
male(charles).
male(mark).
male(philip).
male(andrew).
male(edward).
male(william).
male(peter).
male(james).
female(mum).
female(elizabeth).
female(spencer).
female(margaret).
female(diana).
female(anne).
female(sarah).
female(sophie).
female(zara).
female(beatrice).
female(eugenie).
female(louise).
spouse(george,mum).
spouse(mum,george).
spouse(elizabeth,philip).
spouse(philip,elizabeth).
spouse(spencer,kydd).
spouse(kydd,spencer).
spouse(diana,charles).
spouse(charles,diana).
spouse(anne,mark).
spouse(mark,anne).
spouse(andrew,sarah).
spouse(sarah,andrew).
spouse(edward,sophie).
spouse(sophie,edward).
child(charles,elizabeth).
child(charles,philip).
child(andrew,elizabeth).
child(andrew,philip).
child(edward,elizabeth).
child(edward,philip).
child(william,charles).
child(william,diana).
child(harry,charles).
child(harry,diana).
child(peter,anne).
child(peter,mark).
child(james,edward).
child(james,sophie).
child(margaret,george).
child(margaret,mum).
child(diana,kydd).
child(diana,spencer).
child(elizabeth,george).
child(elizabeth,mum).
child(anne,elizabeth).
child(anne,philip).
child(zara,anne).
child(zara,mark).
child(beatrice,andrew).
child(beatrice,sarah).
child(eugenie,andrew).
child(eugenie,sarah).
child(louise,edward).
child(louise,sophie).
grandchild(X,Y):-child(X,Z),child(Z,Y).
greatgrandparent(X,Y):-grandchild(Y,Z),child(Z,X).
ancestor(A,B):-child(B,A);(child(C,A),ancestor(C,B)).
mthcousinnremoved(X,Y,0,0):- X\=Y,male(Z),child(X,Z),child(Y,Z).
mthcousinnremoved(X,Y,M,0):-child(X,XX),child(Y,YY),mthcousinnremoved(XX,YY,M-1,0).
mthcousinnremoved(X,Y,M,N):-child(X,Z),mthcousinnremoved(Z,Y,M,N-1).
brother(X,Y):-male(X),mthcousinnremoved(X,Y,0,0).
sister(X,Y):-female(X),mthcousinnremoved(X,Y,0,0).
daughter(X,Y):-child(X,Y),female(X).
son(X,Y):-child(X,Y),male(X).
firstcousin(X,Y):-mthcousinnremoved(X,Y,1,0).
brotherinlaw(X,Y):-spouse(Y,Z),brother(X,Z).
sisterinlaw(X,Y):-spouse(Y,Z),sister(X,Z).
aunt(X,Y):-female(X),mthcousinnremoved(X,Y,0,1).
uncle(X,Y):-male(X),mthcousinnremoved(X,Y,0,1).
下为运行结果的消息内容。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
?- grandchild(X,elizabeth),write(X),nl,fail.
william
harry
peter
james
zara
beatrice
eugenie
louise
false.
?- brotherinlaw(X,diana),write(X),nl,fail.
andrew
edward
false.
?- greatgrandparent(X,zara),write(X),nl,fail.
george
mum
false.
?- ancestor(X,eugenie),write(X),nl,fail.
andrew
sarah
elizabeth
philip
george
mum
false.
Related posts