Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,7 @@
bsort :: Ord a => [a] -> [a]
bsort s = case _bsort s of
t | t == s -> t
| otherwise -> bsort t
where _bsort (x:x2:xs) | x > x2 = x2:(_bsort (x:xs))
| otherwise = x:(_bsort (x2:xs))
_bsort s = s

View file

@ -0,0 +1,9 @@
import Data.Maybe (fromMaybe)
import Control.Monad
bsort :: Ord a => [a] -> [a]
bsort s = maybe s bsort $ _bsort s
where _bsort (x:x2:xs) = if x > x2
then Just $ x2 : fromMaybe (x:xs) (_bsort $ x:xs)
else liftM (x:) $ _bsort (x2:xs)
_bsort _ = Nothing

View file

@ -0,0 +1,16 @@
import Data.Maybe (fromMaybe)
import Control.Monad
bubbleSortBy :: (a -> a -> Bool) -> [a] -> [a]
bubbleSortBy f as = case innerSort $ reverse as of
Nothing -> as
Just v -> let (x:xs) = reverse v
in x : bubbleSortBy f xs
where innerSort (a:b:cs) = if b `f` a
then liftM (a:) $ innerSort (b:cs)
else Just $ b : fromMaybe (a:cs)
(innerSort $ a:cs)
innerSort _ = Nothing
bsort :: Ord a => [a] -> [a]
bsort = bubbleSortBy (<)