Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

2nd Edition

1597499471, 978-1597499477

More Books

Students also viewed these Databases questions

Question

d. What language(s) did they speak?

Answered: 1 week ago