Advertisement
OriReschini

Práctica 5

May 22nd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. data Tree a = E | Leaf a | Join (Tree a) (Tree a) deriving Show
  2.  
  3. reduceT f e E = e
  4. reduceT f e (Leaf x) = x
  5. reduceT f e (Join l r) = let (l', r') = ( (reduceT f e l), (reduceT f e r) ) in f l' r'
  6.  
  7. mapreduce f g e E = e
  8. mapreduce f g e (Leaf x) = f x
  9. mapreduce f g e (Join l r) = let (l',r') = ((mapreduce f g e l),(mapreduce f g e r))
  10. in g l' r'
  11.  
  12. combine (a,b,c,d) (u,v,w,x) = (c + v, max b (d + v), max w (x + d), d + x)
  13.  
  14. tupla x = (a,a,a,x)
  15. where
  16. a = max 0 x
  17.  
  18. mcss t = (\(a,b,c,d) -> a) (mapreduce tupla combine (0,0,0,0) t)
  19.  
  20. a = Join (Join (Join (Leaf 1) (Leaf (-1) )) (Leaf 3)) (Join (Leaf 4) (Leaf (-2)))
  21.  
  22. sufijos :: Tree Int -> Tree (Tree Int)
  23.  
  24. sufijos E = Leaf E
  25. sufijos (Leaf x) = Leaf (Leaf x)
  26. sufijos (Join l r) = E
  27.  
  28. conSufijos :: Tree Int -> Tree (Int, Tree Int)
  29. conSufijos (Leaf x) = Leaf (x, sufijos (Leaf x) )
  30. conSufijos (Join l r) = Join (conSufijos l) (conSufijos r)
  31.  
  32. maxT a = reduceT max (minBound :: Int) a
  33.  
  34. a1 = Join (Join (Leaf 10) (Leaf 15)) (Leaf 20)
  35.  
  36. b = Join (Join (Leaf (Join (Leaf 15) (Leaf 20))) (Leaf (Leaf 20) )) (Leaf E)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement