Question: Write the following functions in Picat or Haskell using recursion. No higher-order functions or list comprehensions can be used in the implementations. 1. sorted down(lst):

Write the following functions in Picat or Haskell using recursion. No higher-order functions or list comprehensions can be used in the implementations. 1. sorted down(lst): This function checks if lst is sorted in non-increasing order. For example, for lst = [3,3,2,1], it succeeds. 2. triplets(lst): This function splits lst into 3-element groups from left to right, and returns a list of such groups. If the size of lst is not a multiple of 3, then the last group contains fewer than 3 elements. For example, for lst = [a,b,c,d,e,f,g], the returned list is [[a,b,c],[d,e,f],[g]]. 3. cartesian(xs,ys): This function takes two sets represented as lists, xs and ys, and returns the Cartesian product of the sets, i.e., a set of all possible pairs (x,y), where x is an element of xs and y is an element of ys. For example for xs = [1,2] and ys = [1,2,3], the function returns [(1,1),(1,2),(1,3),(2,1),(2,2),(2,3)]. 4. gen(int n) (extra 5 points): This function returns a list of all possible strings of as and bs that contain more as than bs. For example, for n = 3, it returns: ["aaa","aab","aba","baa"]. The order of the strings in the list is not important.

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!