Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

database of social networking in prolog

Posted on 2008-10-27
2
Medium Priority
?
344 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
2 Comments
 
LVL 46

Accepted Solution

by:
Kent Olsen earned 1500 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

Independent Software Vendors: 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

Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
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 tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

926 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