Run-Length Encoding in Haskell
URL: http://www.haskell.org/haskellwiki/99_questions/1_to_10
Problem 10 of the famous 99 Problems. I got 99 problems, but a Lisp ain't one.
Copy this code and paste it in your HTML
import Data.List
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
letterList
= map nub groupList
in zip lengths letterList
-- from the haskell.org solutions:
encode2
:: (Eq a
) => [a
] -> [(Int, a
)]
Report this snippet