March 2014 update
This commit is contained in:
parent
09687c4926
commit
a25938f123
1846 changed files with 21876 additions and 5203 deletions
16
Task/Combinations/OCaml/combinations-2.ocaml
Normal file
16
Task/Combinations/OCaml/combinations-2.ocaml
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
let comb m xs =
|
||||
let xs = Array.of_list xs in
|
||||
if m > Array.length xs then
|
||||
[]
|
||||
else begin
|
||||
let arr = Array.make (m+1) [] in
|
||||
arr.(0) <- [[]];
|
||||
for j = 0 to Array.length xs - m do
|
||||
for i = 1 to m do
|
||||
arr.(i) <- arr.(i) @ List.map (fun ys -> xs.(j+i-1)::ys) arr.(i-1)
|
||||
done
|
||||
done;
|
||||
arr.(m)
|
||||
end
|
||||
;;
|
||||
comb 3 [0;1;2;3;4];;
|
||||
Loading…
Add table
Add a link
Reference in a new issue