Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. --Aufgabe 1
  2.  
  3. --1
  4.  
  5. quadratic :: ( Int , Int , Int ) -> Int -> Int
  6. quadratic (a,b,c) x = a*(x*x)+b*x+c --wende gleichung an
  7.  
  8. --2
  9.  
  10. square :: Int -> Int
  11. square x
  12. |x==0 =0
  13. |x<0 =square(-x)
  14. |otherwise =x*x --quadriere
  15. --3 a
  16.  
  17. sumList :: [Int] -> Int
  18. sumList [] = 0
  19. sumList (x:xs) = x + sumList xs --rekursiv erstes element addieren
  20.  
  21. --3 b
  22.  
  23. foldList :: ( Double -> Double -> Double ) -> [ Double ] -> Double
  24. foldList (op) [] = 0
  25. foldList (op) (x:xs) = x + foldList (op) xs
  26.  
  27. --3 c
  28.  
  29. mapList :: ( Int -> Int ) -> [ Int ] -> [ Int ]
  30. mapList (func) [] = []
  31. mapList (func) (x:xs) = [func x] ++ mapList (func) xs --an Liste muss ein Teil einer Liste dran damit die Liste länger wird und man eine Liste hat
  32.  
  33. --4
  34.  
  35. tableInt :: ( Int -> Int ) -> [ Int ] -> String
  36. tableInt (func) [] = ""
  37. tableInt (func) (x:xs) = show(x) ++":"++ show(func x) ++ "\n" ++ tableInt(func) xs --gib aus+gib mit fkt aus
  38.  
  39. --Aufgabe 2
  40.  
  41. --1
  42.  
  43. containsList :: [ Int ] -> Int -> Bool
  44. containsList (x:xs) y
  45. |x==y = True --ist element drin
  46. |xs==[] = False -- liste zuende
  47. |otherwise = containsList (xs) y
  48.  
  49. --2
  50.  
  51. import Data.Char ( toLower )
  52. countList :: [ Char ] -> Char -> Int
  53. countList [] c = 0
  54. countList (x:xs) c
  55. |toLower x == c =1+countList (xs) c --counter wird immer hochgezählt, sodass wert am ende 1+1+1+1+1+1+...==X ausgibt
  56. |otherwise = countList (xs) c
  57. --3
  58.  
  59. bubbleSortList :: [ Int ] -> [ Int ]
  60. bubbleSortList [] = []
  61. bubbleSortList (x:xs) = stufe (foldl naechster (x,[]) xs)
  62. where
  63. naechster(y,t) x = (min x y, max x y :t)
  64. stufe(x,t) = x : bubbleSortList t
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement