Anonymous user
Combinations: Difference between revisions
m
→{{header|Haskell}}: Added type signature, improved aesthetics
(Added Haskell example) |
m (→{{header|Haskell}}: Added type signature, improved aesthetics) |
||
Line 25:
Straightforward, unoptimized implementation with divide-and-conquer:
<pre>
comb 0 _ = [[]]▼
comb m (x:xs) = comb m xs ++ map (x:) (comb (m-1) xs)
</pre>
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.
Line 33 ⟶ 36:
To generate combinations of integers between 0 and ''n-1'', use
Similar, for integers between 1 and ''n'', use
=={{header|J}}==
|