Skip to content

Instantly share code, notes, and snippets.

@dtchepak
Created May 22, 2012 03:03
Show Gist options
  • Save dtchepak/2766263 to your computer and use it in GitHub Desktop.
Save dtchepak/2766263 to your computer and use it in GitHub Desktop.
Attempt at prob 11 from 99 Haskell probs
import Data.List (group)
data RunLength a = Single a | Multiple Int a deriving (Show, Eq)
encodeModified :: Eq a => [a] -> [RunLength a]
encodeModified = map runLength . group
where runLength [x] = Single x
runLength xs@(x:_) = Multiple (length xs) x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment