Solved

database of social networking in prolog

Posted on 2008-10-27
2
332 Views
Last Modified: 2012-05-05
I am currently building a social networking stuff, similar like facebook or friendster and  I  a bit stuck in this part where I need to have a predicate that basically says " who is X friends with, through at most two intermediate people, and what is the path?" I have a database in my prolog file which is something like:

fr(chris, geen).
fr(geen,jill).
fr(jill, clark).

I want to create a prolog predicate called friend(X,Y,Z). An example I want it to do something like

friend(chris,clark,L).
L = [chris, geen, jill, clark].
....
and other stuff according what it finds in the database.

I know that I am suppose to use recursion here and backtracking, as well as the cut operation to tell the function to stop when it finds a friend more than 2 bridges. Can someone please help me one this
0
Comment
Question by:kuntilanak
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 45

Accepted Solution

by:
Kent Olsen earned 500 total points
ID: 22814648
In database terms, you'll want to join two friends together, then join all of the friends of one of them.

Friend A has 10 friends, one of which is B.
Freind B has 15 friends, two of which are A and C.  It doesn't matter if C is a friend of A.

Join all of the friends of A and B.  To this list join all of the friends of C.  Friend A is now joined to the friends of C.


Kent
0
 

Author Comment

by:kuntilanak
ID: 22814681
can you help me to code that a bit in prolog.. cause that's where my confusion is
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
This video teaches viewers about errors in exception handling.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question