diff options
| author | Shinya Sato <shinnya.sato@gmail.com> | 2022-05-30 20:36:38 +0900 |
|---|---|---|
| committer | Shinya Sato <shinnya.sato@gmail.com> | 2022-05-30 20:36:38 +0900 |
| commit | e18b27f43ac23689822d4aaaaa3e8d550e41017a (patch) | |
| tree | 262150d7ad6abc6759f41a7adbb6dec4a7c90cb5 /comparison/Haskell | |
| parent | 04cbbcc0649dfc80d8dbf8c4bc567285df7a9da4 (diff) | |
| download | inpla-e18b27f43ac23689822d4aaaaa3e8d550e41017a.tar.gz inpla-e18b27f43ac23689822d4aaaaa3e8d550e41017a.zip | |
v0.8.2-2
Diffstat (limited to '')
| -rw-r--r-- | comparison/Haskell/Makefile | 6 | ||||
| -rw-r--r-- | comparison/Haskell/bsort-20000.hs | 45 | ||||
| -rw-r--r-- | comparison/Haskell/isort-20000.hs | 39 |
3 files changed, 87 insertions, 3 deletions
diff --git a/comparison/Haskell/Makefile b/comparison/Haskell/Makefile index b55259f..13a1b83 100644 --- a/comparison/Haskell/Makefile +++ b/comparison/Haskell/Makefile @@ -1,7 +1,7 @@ CC = stack ghc CFLAGS = -O2 BENCHMARK = bash ../tools/sptest_commands.sh -TARGET = ack3-11 fib38 bsort-40000 isort-40000 qsort-260000 msort-260000 +TARGET = ack3-11 fib38 bsort-20000 isort-20000 qsort-260000 msort-260000 LOG = log.txt @@ -18,10 +18,10 @@ ack3-11: ack3-11.hs fib38: fib38.hs $(CC) -- $(CFLAGS) $< -bsort-40000: bsort-40000.hs +bsort-20000: bsort-20000.hs $(CC) -- $(CFLAGS) $< -isort-40000: isort-40000.hs +isort-20000: isort-20000.hs $(CC) -- $(CFLAGS) $< qsort-260000: qsort-260000.hs diff --git a/comparison/Haskell/bsort-20000.hs b/comparison/Haskell/bsort-20000.hs new file mode 100644 index 0000000..89ecfab --- /dev/null +++ b/comparison/Haskell/bsort-20000.hs @@ -0,0 +1,45 @@ +{- +https://gist.github.com/masquerade0324/68f4f3fd3ab897fbe1ad +http://files.farka.eu/pub/AC21007/lec5.pdf +-} + +import System.Random + +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 n = xs + + +go xs 0 = xs +go xs n = go (bs xs n) (n-1) + +bsort [] = [] +bsort xs = go xs (length xs -1) + +{- +main = print $ bsort [3,2,8,5] +-} + + +randomList :: Int -> IO([Int]) +randomList 0 = return [] +randomList n = do + r <- randomRIO (1,10000) + rs <- randomList (n-1) + return (r:rs) + + +validation [] = True +validation (x:xs) = validation_cons x xs +validation_cons x [] = True +validation_cons x (y:ys) = + if x<=y then validation_cons y ys + else False + + +main = do + list <- randomList 20000 + let sorted = bsort list + print (validation sorted) diff --git a/comparison/Haskell/isort-20000.hs b/comparison/Haskell/isort-20000.hs new file mode 100644 index 0000000..a4cef88 --- /dev/null +++ b/comparison/Haskell/isort-20000.hs @@ -0,0 +1,39 @@ +{- +http://www.codecodex.com/wiki/Insertion_sort#Standard_ML +-} +import System.Random + +isort [] = [] +isort (x:xs) = insert x (isort xs) + +insert x [] = [x] +insert x (y:ys) = + if x<=y then x:y:ys + else y:(insert x ys) + + +{- +main = print $ isort [3,2,8,5] +-} + + +randomList :: Int -> IO([Int]) +randomList 0 = return [] +randomList n = do + r <- randomRIO (1,10000) + rs <- randomList (n-1) + return (r:rs) + + +validation [] = True +validation (x:xs) = validation_cons x xs +validation_cons x [] = True +validation_cons x (y:ys) = + if x<=y then validation_cons y ys + else False + + +main = do + list <- randomList 20000 + let sorted = isort list + print (validation sorted) |
