Self-test 1 solutions

Family tree example with alternatives

              male(alistair).
            male(andrew).
            male(benjamin).
            male(caleb).
            male(david).
            male(james).
            male(john).
    
            female(alison).
            female(ann).
            female(beatrice).
            female(clara).
            female(diana).
            female(jane).
            female(joan).
    
            parent(beatrice, james).
            parent(beatrice, john).
            parent(benjamin, james).
            parent(benjamin, john).
            parent(caleb, benjamin).
            parent(clara, benjamin).
            parent(james, andrew).
            parent(james, ann).
            parent(jane, david).
            parent(jane, diana).
            parent(joan, andrew).
            parent(joan, ann).
            parent(john, david).
            parent(john, diana).
              grandparent(Grandp, Child) :- 
                    parent(Grandp, Parent),
                    parent(Parent, Child).
  1. In the following solutions, it doesn't matter in terms of the correctness of the program if female/1 and male/1 are placed before or after the grandparent/2 goal.
  2.         grandmother(Grannie, Child) :-
                    grandparent(Grannie, Child),
                    female(Grannie).
    
            grandfather(Grandpa, Child) :-
                    grandparent(Grandpa, Child),
                    male(Grandpa).
              ancestor(Current, Anc) :-     % 1
                    parent(Anc, Current).
            ancestor(Current, Anc) :-     % 2
                    parent(Anc, Via),
                    ancestor(Current, Via).
--------------------------------------------------------------------------

Navigation Menu

--------------------------------------------------------------------------