Link to home
Start Free TrialLog in
Avatar of Slapkey
SlapkeyFlag for United States of America

asked on

Identifying members in lists of lists.

Hi.  I am very new to Prolog, but I'm trying to learn it.
I am more famiilar with C, and wrote a program whose output gave me a list of connections between nodes in the form of a matrix, which in its simplest case looks like this:

[ -1,  1]
[  1, -1]

In the example above, Row 1 is Node 1's connections, and -1 means NO connection exists.  Any non-"-1" value means a connection exists.  So in the example above, Node 1 is connected to Node 2 (and Node 2, or Row 2, is subsequently connected to Node 1).

What I'm trying to do in prolog is to be able to supply this list of lists as a variable, say "Data," and have Prolog give me back each node's connections.  
If I give it [-1, 1, 1, 1, -1, -1, 1], I want it to give me the list [Node#, 2, 3, 4, 7], where node# increments as it goes through the lists of Data.

Does that make sense?

I have been against a brick wall for about 3 hours now, trying different things out, but I can never get my rules and predicates to give me what I want.  

I can get the list of lists to get bound correctly, but I cannot come up with something that can get a new list of lists created with the data I want...

Like I said I am very much a beginner at Prolog...it doesn't seem like it should be anywhere near as difficult as it has been for me.

Any thoughts, suggestions?
ASKER CERTIFIED SOLUTION
Avatar of F. Dominicus
F. Dominicus
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Small addition you might like to check one oneline tutorial for Prolog like:
http://www.csupomona.edu/~jrfisher/www/prolog_tutorial/contents.html


Regards
Friedrich
Avatar of Slapkey

ASKER

Thank you very much!  I have been able to take what you gave me and to continue building on it to try and achieve my end-goal with this data.  Hopefully I will be able to complete it now!