Question: We say a list is squished if it is sorted, has no duplicate elements, and does not have any embedded lists. We squish a list

We say a list is squished if it is sorted, has no duplicate elements, and does not have any embedded lists. We squish a list L by first removing all sublists within L and replacing them with their members (e.g.[1,[2,3],4] would become [1,2,3,4], second we remove all duplicate values in the resulting list, and finally we sort the result. Write a Prolog rule squish/2 which squishes a list (without using any built-in functions or rules other than sort/2). For example:
?- squish([1,2,[3,4,[5,6],7],8,9,[2,4,5,8]],[1,2,3,4,5,6,7,8,9]).
true.
?- squish([a,b,c,[d,e],f,[c, a, b]],[d,e,f,c,a,b]).% result not sorted
false.
?- squish([1,[2,3],[4,5,6],7,1,2,3],[1,[2,3],[4,5,6],7]).% result has sublists
false.
?- squish([1,[2,4],[4,[5],6],[5,2,1],[9,4,5],[8,4,2],3],X).
X =[1,2,3,4,5,6,8,9]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!