Posted By

rtperson on 08/18/11


Tagged

problems 99


Versions (?)

Haskell 99 Problems - Numbers 15 and 16


 / Published in: Haskell
 

URL: http://haskell.org/haskellwiki/99_questions/11_to_20

problem 15, Replicate the elements of a list a given number of times.

repli "abc" 3 "aaabbbccc"

problem 16, Drop every N'th element from a list. 
*Main> dropEvery "abcdefghik" 3
    "abdeghk"
  1. repli :: Int -> [a] -> [a]
  2. repli n = concatMap (replicate n)
  3.  
  4.  
  5. dropEvery :: Int -> [a] -> [a]
  6. dropEvery n [] = []
  7. dropEvery n xs
  8. | length xs < n = xs
  9. | otherwise =
  10. let pre = (init . (take n)) xs
  11. post = drop n xs
  12. in pre ++ (dropEvery n post)

Report this snippet  

You need to login to post a comment.