Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help for prolog question

Status
Not open for further replies.

franklintaniredjo

Programmer
Feb 1, 2004
2
CA
Hi, I just started learning lists in prolog and I need help on solving this problem: Come up with a prolog program for flatten(List,FlatList): List can be a list of lists (they can also contain lists inside), and FlatList is List 'flattened' so that the elements of List's sublists (or sub-sublists) are reorganized as one plain list (that has no sublists). Example of queries:

The following all succeed:
flatten([[a],[[]],[[b,[c]],[d]]],[a,b,c,d]).
flatten([[21] | [22,[k | [l,m]]]],[21,22,k,l,m]).


The following fail:
flatten([[a,b]],[b,a]).
flatten([[c,[d]]],[c,[d]]).





Thank you to anyone who can help me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top