### Author Topic: Kinship  (Read 351 times)

#### Galileo

• Jr. Member
•  • Posts: 91 ##### Kinship
« on: 13. April 2018, 19:24:45 »
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.

Code: [Select]
`// Kinship, programmed in Yabasic by Galileo, 06/2011// Translated to english in 04/2018// Inspired in classic Prolog examples// Child/parent relationdata "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 = 10dim peoples\$(numpeople, 2)dim items\$(2)n = 1clear screenwhile(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 ifwendsolution\$ = ""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 subsub 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 subsub 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 subsub is_ancestor\$(person\$, forefather\$) if instr(ancestors\$(person\$), forefather\$) then return "Yes" else return "No" end ifend subsub 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 ifend subsub 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 ifend subsub 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 ifend subsub 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 ifend 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 subcolor\$ = "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`