Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Data.Char
- let2int :: Char -> Int
- let2int c = ord (c)
- int2let :: Int -> Char
- int2let i = chr (i)
- shift :: Int -> Char -> Char
- shift i c | ((ord (c)>96) && (ord (c) < 123)) = chr (ord (c)+i)
- | otherwise = c
- encode :: Int -> String -> String
- encode i (c:[]) = [(shift i c)]
- encode i (c:s) = [(shift i c)] ++ (encode i s)
- table :: [Float]
- table = [8.2, 1.5, 2.8, 4.3, 12.7, 2.2, 2.0, 6.1, 7.0, 0.2, 0.8, 4.0, 2.4, 6.7, 7.5, 1.9, 0.1, 6.0,
- 6.3, 9.1, 2.8, 1.0, 2.4, 0.2, 2.0, 0.1]
- freqs :: String -> [Float]
- freqs s = freqs' (s) ([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]) --geht hoffentlich auch einfacher
- freqs' :: String -> [Int] -> [Float] --absolute Häufigkeit
- freqs' [] xs = freqs'' (sum (xs)) (xs) --wenn Liste abgearbeitet: an freqs'' weitergeben
- freqs' (c:s) xs = (freqs' (s) (ys)) where --Nimmt nach und nach Elemente raus und sortiert diese in die Liste ys ein
- ys | (ord (c) > 96) && (ord (c) < 123) = replaceNth ((ord (c))-97) (xs !! ((ord (c))-97)) xs --Liste an c um 1 erhöhen
- | otherwise = xs --kein Buchstabe
- freqs'' :: Int -> [Int] -> [Float] --relative Häufigkeit
- freqs'' _ [] = [] --Abbruchbedingung
- freqs'' i (x:xs) = (fromIntegral(x) / fromIntegral (i)) : (freqs'' i xs) --Teilt absolute Häufigkeit des einzelnen Buchstabens durch die Anzahl an Buchstaben insgesamt und reiteriert freqs'' ohne dem Buchstaben
- replaceNth :: Int -> Int -> [Int] -> [Int] --Stelle -> neues Ergebnis -> Liste -> modifizierte Liste
- replaceNth n newVal (x:xs) -- Quelle: http://stackoverflow.com/questions/5852722/replace-individual-list-elements-in-haskell
- | n == 0 = newVal:xs
- | otherwise = x:replaceNth (n-1) newVal xs
- chisqr :: [Float] -> [Float] -> Float
- chisqr [] [] = 0 --Abbruchbedingung
- chisqr [] _ = error "Listen nicht gleich lang"
- chisqr _ [] = error "Listen nicht gleich lang"
- chisqr (x:xs) (y:ys) = chisqr xs ys + ((x-y)^2/y)
- rotate :: Int -> [a] -> [a]
- rotate _ [] = [] --nur für den Fall...
- rotate 0 xs = xs --Abbruchbedingung
- rotate n (x:xs) = rotate (n-1) (xs++[x])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement