Combinations: Difference between revisions

Content deleted Content added
No edit summary
Line 1,023:
 
In the induction step, either ''x'' is not in the result and the recursion proceeds with the rest of the list ''xs'', or it is in the result and then we only need ''m-1'' elements.
 
Shorter version of the above:
<lang haskell>import Data.List (tails)
 
comb :: Int -> [a] -> [[a]]
comb 0 _ = [[]]
comb m l = concat [map (x:) (comb (m-1) xs) | (x:xs) <- tails l]</lang>
 
To generate combinations of integers between 0 and ''n-1'', use