Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Clojure, write a function, (column table n), where n < (count (first table)) is a number and table is a non-empty vector of vectors.

In Clojure, write a function, (column table n), where n < (count (first table)) is a number and table is a non-empty vector of vectors. All nested vectors in table will have the same non-zero size. That is, table is a matrix. Return a seq containing the elements of the n-th column (zero-based indexing) of table.(Useful: map, nth)

Sample runs:

> (def table [[1 2 a b] [3 4 c d] [x y p z]])

> (column table 0) (1 3 x)

> (column table 1) (2 4 y)

> (column table 3) (b d z)

2.Create a function of 3 arguments, (merge-pred pred lst1 lst2), where pred is a predicate function of two arguments, and lst1 and lst2 are lists. pred will indicate an ordering relationship. (pred a b) returns true if and only if a p b and returns false otherwise. The arguments lst1 and lst2 must already be sorted in increasing order according to pred. In the event of a tie (pred considers two elements to be equal), the elements from lst1 should appear before the tied elements of lst2. Note: equal does not mean the same. For example, if pred compares elements based on their string length, hello and olleh would be considered equal. The return value of merge-pred should be the results of merging the elements of the lists in sorted order (according to pred).

Sample runs:

> (merge-pred <= (1 4) (1 2 8))

(1 1 2 4 8)

> (merge-pred #(<= (count %1) (count %2)) ("a" "ab" "abcdef") ("c" "abc"))

("a" "c" "ab" "abc" "abcdef")

3. (Useful: take, drop) Create a function of 2 arguments, (sort-pred pred lst) where pred is an ordering predicate as described in the previous problem and lst is a list. The return result of sort-pred should be the elements of lst in increasing order according to pred. In the event of a tie (pred considers two elements to be equal), the resulting order of the elements may be ambiguous. You may not use any of Clojures built-in sorting functions or consult their source code in your solution.

Sample runs:

> (sort-pred <= (8 9 5 -1 0 2 3 -15))

(-15 -1 0 2 3 5 8 9)

> (sort-pred >= (8 9 5 -1 0 2 3 -15))

(9 8 5 3 2 0 -1 -15)

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

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions

Question

=+2 Why are international employment standards important to IHRM?

Answered: 1 week ago