-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pseudocode.txt
67 lines (43 loc) · 2.25 KB
/
Pseudocode.txt
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
START
Create nodes that have a name, a pointer to their parent, a boolean for whether they have been marked as seen, and the number of hops to get there
primaryTraversal(secondNode*, 0)
markSearch(firstNode*, 0)
INT depth = traversalHops - searchHops
INT partial_consanguinity = ((traversalHops + searchHops) - |depth|) / 2
PRINT name of firstNode concatenated with " is the ", findFullConsanguinity(partial_consanguinity, depth), " of ", name of secondNode
cleanTraversal(firstNode*)
END
FUNCTION primaryTraversal(node*, traversalHops):
SET hops OF node TO traversalHops
SET marked TO true
IF parent OF node IS NULL, THEN RETURN
ELSE primaryTraversal(parent*, traversalHops + 1)
FUNCTION cleanTraversal(node*):
SET marked TO false
IF parent OF node IS NULL, THEN RETURN
ELSE cleanTraversal(parent*)
FUNCTION markSearch(node*, searchHops):
IF node IS marked, THEN RETURN searchHops AS WELL AS hops OF node
ELSE RETURN markSearch(parent*, searchHops + 1)
FUNCTION findFullConsanguinity(partial_consanguinity, depth):
CASE partial_consanguinity OF:
0 :
IF depth IS 0 THEN RETURN "self"
ELSE IF depth IS < 0 THEN RETURN findGeneration(depth) concat with "child"
ELSE IF depth IS > 0 THEN RETURN findGeneration(depth) concat with "parent"
1:
IF depth IS 0 THEN RETURN "sibling"
ELSE IF depth IS < 0 THEN RETURN findParentOrSiblingGeneration(depth) concat with "nephew/niece"
ELSE IF depth IS > 0 THEN RETURN findParentOrSiblingGeneration(depth) concat with "uncle/aunt"
OTHERWISE:
IF partial_consanguinity IS < 1, THEN:
INT numberCousin = partial_consanguinity - 1
INT timesRemoved = |depth| + numberCousin - 1
IF timesRemoved IS == 0, THEN RETURN ORDINAL FORM OF numberCousin concat with " cousin"
ELSE RETURN ORDINAL FORM OF numberCousin concat with " cousin ", timesRemoved, and " times removed"
FUNCTION findGeneration(depth):
IF |depth| IS == 1, THEN RETURN "grand"
ELSE IF |depth| IS GREATER THAN 1:
STRING greats = ""
FOR depth TIMES, concat "great " with greats
RETURN greats concat with "grand"