Advertisement
PonaFly

lab 3

Nov 7th, 2016
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Data.List
  2. -- 1
  3. counteven lst = (length (filter even lst))
  4.  
  5. -- 2
  6. takeMax lst =  length (takeWhile (< maximum lst) lst)
  7.  
  8. --3
  9. insertE lst n  | elem n lst  =  lst
  10.                | otherwise =  let new = span ( < n ) lst in
  11.   ( (fst new ) ++ [n] ++ (snd new) )
  12.  
  13. -- 4
  14. sortedLst lst = sort lst == lst
  15.  
  16. --5
  17. secondMax lst = maximum  (filter  ( /= (maximum lst) ) lst)
  18.  
  19. --7
  20. maxPos lst =  fst ( foldl(\(mx,k) el -> if el > 0 then  (mx,k+1)
  21.                                   else
  22.                                    if mx > k then (mx,0)
  23.                                    else (k,0) )
  24.                                   (0,0) (lst ++ [(-1)]))
  25.  
  26.  
  27. --6
  28. shell lst = let
  29.  new = transpose lst
  30.  a = map maximum new
  31.  b = map minimum new
  32.  in a:[b]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement