Advertisement
Guest User

Untitled

a guest
Aug 1st, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. --Aufgabe 1
  3.  
  4. (\\) :: [a]->[a]->[a]
  5. (\\) b [] = b
  6. (\\) [] z = []
  7. (\\) (x:xs) (y:ys)
  8.                     | elem x (y:ys) = xs \\(y:ys)
  9.                     |otherwise = x: (xs \\ (y:ys))
  10.                    
  11. (\\) :: [a] -> [a] -> [a]
  12. (\\) x y = [s | s <- x , not (elem s y) ]
  13.  
  14. smallestNatNotIn :: [a]-> a
  15. smallestNatNotIn x = head ([1..(maximum x)] \\ x)
  16.  
  17. -- Da die Funkiom (\\) quadratisch ist, da er mit n(x) elementen n(y) elemente prüft,
  18. -- hat diese Funktion einen uadratischen Aufwand und somit auch die Funkion smallestNatNotIn ,
  19. -- da in ihr die Funktion (\\) aufgerufen wird. -> O(n^2)
  20.  
  21. --Aufgabe2 Addition fehlt
  22.  
  23. data QRational = Q ZInt ZInt deriving Show
  24.  
  25. qadd ::
  26.  
  27. qmult:: QRational -> QRational -> QRational
  28. qmult (Q a b) (Q c d) = Q (zmult a c) (zmult b d)
  29.  
  30. qquotient :: QRational -> QRational -> QRational
  31. qquotient (Q a b) (Q c d) = qmult (Q a b ) (qreciprocal Q c d)
  32.  
  33. qreciprocal :: QRational -> QRational
  34. qrecoprocal Q  b c
  35.                      | zsimplify b == Z Zero Zero = error " division für mit NULL nicht definiert"
  36.                      | otherwise = Q c b
  37.  
  38.  --Aufgabe3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement