franklintaniredjo
Programmer
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.
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.