Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Splits haskell function This is my combinations function I have already combinat

ID: 3828651 • Letter: S

Question

Splits haskell function

This is my combinations function I have already

combinations :: Int -> [a] -> [[a]]
combinations 0 _ = [[]]
combinations _ [] = []
combinations n (x:xs) = (map (x:) (combinations (n-1) xs)) ++ (combinations n xs)

any help would be great

Recall that the function combinations takes a list ofelements of typeclass Ord and an integer k as its arguments and returns a list of (R) length k lists representing all possible subsets of size k. The function splits is similar, except that, given a list of elements of length n, it returns a list of pairs of lists. The first component of the pair represents a combination of length k. The second component represents the complementary combination of length n-k. Two combinations are complementary when their union is equal to the original list. For example, Main :t splits splits (Ord a) [a] (Cal, Cal) Mains splits abc ("c", "ab"), ("b", "ac"), ("bc", "a"), ("a", "bec"), ("ac", "b"), ("ab c")

Explanation / Answer

import Data.Ord (comparing)


wds :: [String]
wds = ["ABC", "EF", "GHIJ", "K"]

main :: IO ()
main = print $ argim (comparing length) wds

argim
:: Foldable t
=> (a -> a -> Ordering) -> t a -> a
argim cmp =
let min_ x y =
case cmp x y of
LT -> x
_ -> y
in foldr1 min_

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote