Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Database rule help!

Status
Not open for further replies.

lagg

Technical User
Oct 14, 2002
111
IE
i need help with a prolog rule. The database is outlined as follows

is_below(bob,jim).
is_below(jim,dave).
is_below(dave,sam).
is_below(sam,pete).
is_below(pete,colin).
is_below(colin,eric).
is_below(eric,steve).
is_below(steve,paul).
is_below(paul,jack).

It shows the rank people, bob is 1 place lower than Jim etc. I want to write a rule which returns the highest person?
top_person(X)
and also a rule to check if one person is higher than the next
higher(colin,jack).
Can you give me some help please?
 
top_person(X) :-
is_bewlow(_,X),
not(is_below(X,_)).


higher(X,Y) :-
bewlow(Y,X).
higher(X,Y) :-
below(Y,X1),
higher(X,X1).

this of course only works if is_below(X,Y) means that X is below Y, so Y is higher than X. Why do i say this? because u didnt say how to interpret ur fact is_below/2. if its reverse u have to change the predicates i made
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top