Haskell 99 Problems - Numbers 15 and 16


/ Published in: Haskell
Save to your folder(s)

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"


Copy this code and paste it in your HTML
  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)

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.