elvecent

Lab3

Nov 8th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. countEven :: Integral a => [a] -> Integer
  2. countEven = length . filter even
  3.  
  4. countUntilMax :: Ord a => a -> Integer
  5. countUntilMax xs = length $ takeWhile (/= m) xs
  6.                    where m = maximum xs
  7.  
  8. secondMax :: Ord a => [a] -> a
  9. secondMax xs = maximum $ filter (/= m) xs
  10.                where m = maximum xs
  11.  
  12. applyList :: [(a -> a -> a)] -> [[a]] -> [a]
  13. applyList fs xxs = foldl1 (\acc xs -> zipWith ($) fs' (zip acc xs)) xxs
  14.                   where fs' = map uncurry fs
  15.  
  16. arrange2 :: a -> a -> Int -> [[a]]
  17. arrange2 x y n = foldl (\acc _ -> map (x :) acc ++ (map (y :) acc)) [[]] [1..n]
  18.  
  19. parallelotope :: Ord a => [[a]] -> [[a]]
  20. parallelotope xxs = foldl (\acc fs -> (applyList fs xxs) : acc) [] ffs
  21.                     where ffs = arrange2 max min n
  22.                           n = length $ head xxs
Add Comment
Please, Sign In to add comment