Return to Snippet

Revision: 50332
at August 18, 2011 04:03 by rtperson


Updated Code
repli :: Int -> [a] -> [a]
repli n = concatMap (replicate n)


dropEvery :: Int -> [a] -> [a]
dropEvery n [] = []
dropEvery n xs 
    | length xs < n = xs
    | otherwise = 
            let pre = (init . (take n)) xs
                post = drop n xs
            in pre ++ (dropEvery n post)

Revision: 50331
at August 18, 2011 03:59 by rtperson


Initial Code
repli :: Int -> [a] -> [a]
repli n = concatMap (replicate n)


dropEvery n [] = []
dropEvery n xs = 
    let pre = (init . (take n)) xs
        post = drop n xs
    in pre ++ (dropEvery n post)

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

Initial Description
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"

Initial Title
Haskell 99 Problems - Numbers 15 and 16

Initial Tags


Initial Language
Haskell