Question: Write a Prolog Program. flat(List,FlatList): List is a given list of lists (they can also contain lists inside), and FlatList is a List flattened so
Write a Prolog Program.
flat(List,FlatList): List is a given list of lists (they can also contain lists inside), and FlatList is a List flattened so that the elements of Lists sublists (or sub-sublists) are reorganized as one plain list (that has no sublists), but the sequence of elements remains the same. You can assume in your program that there are no occurrences of empty lists in List, but List can be empty. Examples of queries:
Please answer in detail! Thanks
The following all succeed flat ([[[a] I [z]], [[b, [c]], [d] ] ], [a, z,b,c,d]) flat ([ [21] [22, [k I [l,m] ] ] ], [21,22, k, 1,m]) . The following fail flat (I[a, b],b,al) flat ([[c, [d] ]], [c, [d]]). The following to test: ?- flat ([[k], [[l]], [m [n] ] ],L). The following all succeed flat ([[[a] I [z]], [[b, [c]], [d] ] ], [a, z,b,c,d]) flat ([ [21] [22, [k I [l,m] ] ] ], [21,22, k, 1,m]) . The following fail flat (I[a, b],b,al) flat ([[c, [d] ]], [c, [d]]). The following to test: ?- flat ([[k], [[l]], [m [n] ] ],L)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
