diff options
| -rw-r--r-- | HsBot.hs | 16 |
1 files changed, 14 insertions, 2 deletions
@@ -122,11 +122,23 @@ userKarma user = userKarma' (userPts user) (userPerc user) where userKarma' pts perc = let cands = sort $ filter (\x -> minPts x <= pts && minPerc x <= perc) (karmas makeConf) in karmaName $ cands !! 0 -- Best posible karma - + +-- Sorts a list sort :: (Ord a) => [a] -> [a] sort [] = [] sort (x:xs) = sort (filter (>= x) xs) ++ [x] ++ sort (filter (< x) xs) +uniq :: (Eq a) => [a] -> [a] +uniq list = + let r = u' list 0 + u' [] _ = [] + u' (x:list) n + | member x r n = u' list n + | otherwise = x:(u' list (n + 1)) + member e list 0 = False + member y (x:list) n = x == y || member y list (n - 1) + in r + split :: String -> Char -> [String] split [] delim = [""] split (c:cs) delim @@ -136,7 +148,7 @@ split (c:cs) delim -- Returns a list of all strings to increase or decrease the karma of matches :: String -> String -> [String] -matches search string = +matches search string = uniq $ case m' $ occ search string of (list, "") -> list (list, rest) -> list ++ (matches search rest) |
