Return to Snippet

Revision: 49748
at July 29, 2011 06:08 by rtperson


Initial Code
import Data.List

thing :: String
thing = "aaaabccaadeeee"

-- My attempt got me close enough to consider it solved.
encode :: (Eq a) => [a] -> [(Int, [a])]
encode xs = 
    let groupList = groupBy (\x y -> x == y) xs
        lengths = map length groupList
        letterList = map nub groupList
    in zip lengths letterList
    
-- from the haskell.org solutions:
encode2 :: (Eq a) => [a] -> [(Int, a)]
encode2 = map (\x -> (length x, head x)) . group

Initial URL
http://www.haskell.org/haskellwiki/99_questions/1_to_10

Initial Description
Problem 10 of the famous 99 Problems. I got 99 problems, but a Lisp ain't one.

Initial Title
Run-Length Encoding in Haskell

Initial Tags


Initial Language
Haskell