Advertisement
Guest User

shitty ass language

a guest
May 26th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Data.Char
  2.  
  3. let2int :: Char -> Int
  4. let2int c = ord (c)
  5.  
  6. int2let :: Int -> Char
  7. int2let i = chr (i)
  8.  
  9. shift :: Int -> Char -> Char
  10. shift i c   | ((ord (c)>96) && (ord (c) < 123)) = chr (ord (c)+i)
  11.             | otherwise = c
  12.  
  13. encode :: Int -> String -> String
  14. encode i (c:[]) = [(shift i c)]
  15. encode i (c:s) = [(shift i c)] ++ (encode i s)
  16.  
  17. table :: [Float]
  18. 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,
  19.          6.3, 9.1, 2.8, 1.0, 2.4, 0.2, 2.0, 0.1]
  20.          
  21. freqs :: String -> [Float]
  22. 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
  23.  
  24. freqs' :: String -> [Int] -> [Float] --absolute Häufigkeit
  25. freqs' [] xs = freqs'' (sum (xs)) (xs) --wenn Liste abgearbeitet: an freqs'' weitergeben
  26. freqs' (c:s) xs = (freqs' (s) (ys)) where --Nimmt nach und nach Elemente raus und sortiert diese in die Liste ys ein
  27.    ys  | (ord (c) > 96) && (ord (c) < 123) = replaceNth ((ord (c))-97) (xs !! ((ord (c))-97)) xs --Liste an c um 1 erhöhen
  28.        | otherwise = xs --kein Buchstabe
  29.  
  30. freqs'' :: Int -> [Int] -> [Float] --relative Häufigkeit
  31. freqs'' _ [] = [] --Abbruchbedingung
  32. 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
  33.  
  34. replaceNth :: Int -> Int -> [Int] -> [Int] --Stelle -> neues Ergebnis -> Liste -> modifizierte Liste
  35. replaceNth n newVal (x:xs) -- Quelle: http://stackoverflow.com/questions/5852722/replace-individual-list-elements-in-haskell
  36.     | n == 0 = newVal:xs
  37.     | otherwise = x:replaceNth (n-1) newVal xs
  38.    
  39. chisqr :: [Float] -> [Float] -> Float
  40. chisqr [] [] = 0 --Abbruchbedingung
  41. chisqr [] _ = error "Listen nicht gleich lang"
  42. chisqr _ [] = error "Listen nicht gleich lang"
  43. chisqr (x:xs) (y:ys) =  chisqr xs ys + ((x-y)^2/y)
  44.  
  45. rotate :: Int -> [a] -> [a]
  46. rotate _ [] = [] --nur für den Fall...
  47. rotate 0 xs = xs --Abbruchbedingung
  48. rotate n (x:xs) = rotate (n-1) (xs++[x])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement