all tasks

This commit is contained in:
Ingy döt Net 2013-04-11 01:07:29 -07:00
parent b83f433714
commit 68f8f3e56b
14735 changed files with 178959 additions and 0 deletions

View file

@ -0,0 +1,21 @@
let rec split_at n xs =
match n, xs with
0, xs ->
[], xs
| _, [] ->
failwith "index too large"
| n, x::xs when n > 0 ->
let xs', xs'' = split_at (pred n) xs in
x::xs', xs''
| _, _ ->
invalid_arg "negative argument"
let rec merge_sort cmp = function
[] -> []
| [x] -> [x]
| xs ->
let xs, ys = split_at (List.length xs / 2) xs in
List.merge cmp (merge_sort cmp xs) (merge_sort cmp ys)
let _ =
merge_sort compare [8;6;4;2;1;3;5;7;9]