Hello.
This is a program I did a few years ago. I've done a little work on it and translated it from Spanish into English.
I hope you find it interesting.
// Kinship, programmed in Yabasic by Galileo, 06/2011
// Translated to english in 04/2018
// Inspired in classic Prolog examples
// Child/parent relation
data "Anthoni/John", "Anthoni/Joana", "Leonard/John", "Leonard/Joana", "Peter/John", "Bethy/Da. Bethy"
data "Peter/Joana", "Elizabeth/John", "Elizabeth/Joana", "Susan/John", "Susan/Joana", "Alex/Anthoni", "Bethy/Frank"
data "Alex/Bethy", "Alice/Anthoni", "Alice/Bethy", "David/Leonard", "David/Mari", "Laura/Leonard", "Laura/Mari"
data "Bob/Frank", "Bob/Da. Bethy", "Tony/Frank", "Tony/Da. Bethy", ""
numpeople = 10
dim peoples$(numpeople, 2)
dim items$(2)
n = 1
clear screen
while(true)
read crowd$
if crowd$ = "" then
numpeople = numpeople - 1
break
end if
void = split(crowd$, items$(), "/")
peoples$(n, 1) = items$(1) : peoples$(n, 2) = items$(2)
n = n + 1
if n > numpeople then
numpeople = numpeople + 1
redim peoples$(numpeople, 2)
end if
wend
solution$ = ""
sub parents$(individual$)
local x, solution$
for x = 1 to numpeople
if peoples$(x, 1) = individual$ then
if solution$ = "" then
solution$ = peoples$(x, 2)
else
solution$ = solution$ + "," + peoples$(x, 2)
end if
end if
next x
return solution$
end sub
sub childs$(individual$)
local x, solution$
for x = 1 to numpeople
if peoples$(x, 2) = individual$ then
if solution$ = "" then
solution$ = peoples$(x, 1)
else
solution$ = solution$ + "," + peoples$(x, 1)
end if
end if
next x
return solution$
end sub
sub ancestors$(individual$)
local x, solution$, sol2$
for x = 1 to numpeople
if peoples$(x, 1) = individual$ then
if solution$ = "" then
solution$ = peoples$(x, 2)
else
solution$ = solution$ + "," + peoples$(x, 2)
end if
sol2$ = ancestors$(peoples$(x, 2))
if sol2$ <> "" then
solution$ = solution$ + "," + sol2$
end if
end if
next x
return solution$
end sub
sub is_ancestor$(person$, forefather$)
if instr(ancestors$(person$), forefather$) then
return "Yes"
else
return "No"
end if
end sub
sub grandparents$(individual$)
local items$(2), x, n, solution$
solution$ = parents$(individual$)
x = split(solution$, items$(), ",")
solution$ = ""
if x > 0 then
for n = 1 to x
solution$ = solution$ + parents$(items$(n)) + ","
next n
return left$(solution$, len(solution$) - 2)
else
return ""
end if
end sub
sub siblings$(individual$)
local items$(2), x, i, solution$, ind$
solution$ = parents$(individual$)
x = split(solution$, items$(), ",")
solution$ = ""
if x > 0 then
for i = 1 to numpeople
if (peoples$(i, 1) <> individual$) and ((peoples$(i, 2) = items$(1)) or (peoples$(i, 2) = items$(2))) then
for x = 1 to i
if not instr(solution$, peoples$(i, 1)) then
solution$ = solution$ + peoples$(i, 1) + ","
end if
next x
end if
next i
return left$(solution$, len(solution$) - 1)
else
return ""
end if
end sub
sub aunties$(individual$)
local items$(2), x, i, solution$, sol2$
solution$ = parents$(individual$)
x = split(solution$, items$(), ",")
solution$ = ""
if x > 0 then
for i = 1 to x
sol2$ = siblings$(items$(i))
if sol2$ <> "" then
solution$ = solution$ + sol2$ + ","
end if
next i
return left$(solution$, len(solution$) - 1)
else
return ""
end if
end sub
sub cousins$(individual$)
local items$(2), x, i, solution$, sol2$
solution$ = aunties$(individual$)
x = split(solution$, items$(), ",")
solution$ = ""
if x > 0 then
for i = 1 to x
sol2$ = childs$(trim$(items$(i)))
if sol2$ <> "" then
solution$ = solution$ + sol2$ + ","
end if
next i
return left$(solution$, len(solution$) - 1)
else
return ""
end if
end sub
// Questions to the family database.
sub demonstration(s$, p$)
local c$
if color$ = "" then c$ = "cyan" else c$ = color$ end if
print color(c$) execute$(s$, p$)
end sub
color$ = "yellow"
print "parents of Alice: "; : demonstration("parents$", "Alice")
print "grandparents of David: "; : demonstration("grandparents$", "David")
print "siblings of David: "; : demonstration("siblings$", "David")
print "aunties of Alex: "; : demonstration("aunties$", "Alex")
print "ancestors of David: "; : demonstration("ancestors$", "David")
print "Tony "; : if is_ancestor$("David","Tony") = "No" then print color(color$) "not "; end if : print color(color$) "is"; : print " ancestor of David"
print "childs of Anthoni: "; : demonstration("childs$", "Anthoni")
print "cousins of Alex: "; : demonstration("cousins$", "Alex")
print