Solved

database of social networking in prolog

Posted on 2008-10-27
2
333 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

729 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