aboutsummaryrefslogtreecommitdiff
path: root/comparison/OCaml/bsort20000.ml
diff options
context:
space:
mode:
authorShinya Sato <shinnya.sato@gmail.com>2022-05-30 20:36:38 +0900
committerShinya Sato <shinnya.sato@gmail.com>2022-05-30 20:36:38 +0900
commite18b27f43ac23689822d4aaaaa3e8d550e41017a (patch)
tree262150d7ad6abc6759f41a7adbb6dec4a7c90cb5 /comparison/OCaml/bsort20000.ml
parent04cbbcc0649dfc80d8dbf8c4bc567285df7a9da4 (diff)
downloadinpla-e18b27f43ac23689822d4aaaaa3e8d550e41017a.tar.gz
inpla-e18b27f43ac23689822d4aaaaa3e8d550e41017a.zip
v0.8.2-2
Diffstat (limited to 'comparison/OCaml/bsort20000.ml')
-rw-r--r--comparison/OCaml/bsort20000.ml39
1 files changed, 39 insertions, 0 deletions
diff --git a/comparison/OCaml/bsort20000.ml b/comparison/OCaml/bsort20000.ml
new file mode 100644
index 0000000..29a369c
--- /dev/null
+++ b/comparison/OCaml/bsort20000.ml
@@ -0,0 +1,39 @@
+open Format
+
+let rec bs (alist : int list) n =
+ match alist with
+ (x::y::ys) ->
+ if x<y then x::(bs (y::ys) (n-1))
+ else y::(bs (x::ys) (n-1))
+ | xs -> xs;;
+
+
+let rec go xs n =
+ match n with
+ 0 -> xs
+ | n -> go (bs xs n) (n-1);;
+
+let bsort alist =
+ match alist with
+ [] -> []
+ | xs -> go xs (List.length(xs) - 1);;
+
+
+let rec mkRandList n =
+ match n with
+ 0 -> []
+ | n -> (Random.int 10000)::(mkRandList (n-1));;
+
+
+let rec validation alist =
+ let rec validation_cons x blist =
+ match blist with
+ [] -> true
+ | y::ys -> if x<=y then (validation_cons y ys) else false
+ in
+ match alist with
+ [] -> true
+ | x::xs -> validation_cons x xs;;
+
+
+let () = print_bool (validation (bsort (mkRandList 20000)));;