We help IT Professionals succeed at work.

Identifying members in lists of lists.

Slapkey
Slapkey asked
on
575 Views
Last Modified: 2008-01-09
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?
Comment
Watch Question

CEO/Programmer
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
fridomCEO/Programmer
CERTIFIED EXPERT

Commented:
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

Author

Commented:
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!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.