RosettaCodeData/Task/Combinations/Haskell/combinations-7.hs

13 lines
251 B
Haskell

comb :: Int -> [a] -> [[a]]
comb m xs = combsBySize xs !! m
where
combsBySize = foldr f ([[]] : repeat [])
f x next =
zipWith
(<>)
(fmap (x :) <$> ([] : next))
next
main :: IO ()
main = print $ comb 3 [0 .. 4]