Created
March 15, 2011 07:10
-
-
Save kisielk/870412 to your computer and use it in GitHub Desktop.
Our candidate programming problem, implemented in Haskell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Data.List | |
| normalizedScore :: String -> String -> Float | |
| normalizedScore a b = fromIntegral (numSimilar a b) / fromIntegral (length a) | |
| numSimilar :: String -> String -> Int | |
| numSimilar a b = sum $ map fromEnum $ zipWith (==) a b | |
| slice :: Int -> Int -> [a] -> [a] | |
| slice from to xs = take (to - from + 1) (drop from xs) | |
| slices :: Int -> [a] -> [[a]] | |
| slices l xs = [slice a (a+l-1) xs | a <- [0 .. length xs - l]] | |
| nbest :: Int -> String -> String -> [(Float, String)] | |
| nbest n a b = take n $ reverse $ sort $ map (\x -> (normalizedScore a x, x)) $ slices (length a) b |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
was able to remove the similarity function and replace it with fromEnum