Advertisement
fsimen

CIS194 Homework3 Local Maxima

May 14th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. splitList :: [a] -> [[a]]
  2. splitList [] = [[]]
  3. splitList list = scanr (\elem new -> [elem] ++ new) [] list
  4.  
  5. selectFirst:: Int -> [[a]] -> [[a]]
  6. selectFirst n [[]] = [[]]
  7. selectFirst n list = map (take n) (filter (\l -> length l >= 3) list)
  8.  
  9. cmpElem::(a -> a -> Bool) -> a -> a -> a -> Bool
  10. cmpElem f a b c = (f a b) && (f c b)
  11.  
  12. localMaxima :: [Integer] -> [Integer]
  13. localMaxima l = let split_list = splitList l
  14. three_elem_list = selectFirst 3 split_list
  15. valid_elem_list = filter (\[a, b, c] -> cmpElem (<) a b c) three_elem_list
  16. in map (\[a, b, c] -> b) valid_elem_list
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement