aboutsummaryrefslogtreecommitdiff
path: root/comparison/SML/bsort-20000.sml
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/SML/bsort-20000.sml
parent04cbbcc0649dfc80d8dbf8c4bc567285df7a9da4 (diff)
downloadinpla-e18b27f43ac23689822d4aaaaa3e8d550e41017a.tar.gz
inpla-e18b27f43ac23689822d4aaaaa3e8d550e41017a.zip
v0.8.2-2
Diffstat (limited to 'comparison/SML/bsort-20000.sml')
-rw-r--r--comparison/SML/bsort-20000.sml42
1 files changed, 42 insertions, 0 deletions
diff --git a/comparison/SML/bsort-20000.sml b/comparison/SML/bsort-20000.sml
new file mode 100644
index 0000000..2129cd6
--- /dev/null
+++ b/comparison/SML/bsort-20000.sml
@@ -0,0 +1,42 @@
+(*
+https://gist.github.com/masquerade0324/68f4f3fd3ab897fbe1ad
+*)
+
+fun bs xs 0 = xs
+ | bs (x::y::ys) n =
+ if (x<y) then x::(bs (y::ys) (n-1))
+ else y::(bs (x::ys) (n-1))
+ | bs xs _ = xs;
+
+fun go xs 0 = xs
+ | go xs n = go (bs xs n) (n-1);
+
+
+fun bsort [] = []
+ | bsort xs = go xs (length(xs) - 1);
+
+
+(* Creates a random list *)
+local
+ val nextInt = Random.randRange(1,10000);
+ val r = Random.rand(1,1);
+in
+ fun mkRandList 0 = []
+ | mkRandList n = (nextInt r)::(mkRandList (n-1))
+end;
+
+
+(* Validation checks *)
+fun validation [] = true
+ | validation (x::xs) =
+ let fun validation_cons x [] = true
+ | validation_cons x (y::ys) =
+ if x<=y then validation_cons y ys
+ else false
+ in
+ validation_cons x xs
+ end;
+
+
+(* Main *)
+validation(bsort(mkRandList 20000));