diff options
author | Joe Zhao <ztuowen@gmail.com> | 2015-02-22 21:29:20 +0800 |
---|---|---|
committer | Joe Zhao <ztuowen@gmail.com> | 2015-02-22 21:29:20 +0800 |
commit | b499ed76f85c0384ecae9922128188717f0d3631 (patch) | |
tree | 2a60cf3577dbb78c21abc21c7279f27ff1d00205 | |
parent | 0b4166fc180939874a61884aa76d2dfe53658da4 (diff) | |
download | h99-b499ed76f85c0384ecae9922128188717f0d3631.tar.gz h99-b499ed76f85c0384ecae9922128188717f0d3631.tar.bz2 h99-b499ed76f85c0384ecae9922128188717f0d3631.zip |
+p9
-rw-r--r-- | p9.hs | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -0,0 +1,13 @@ +pack :: (Eq a) => [a] -> [[a]] +pack = foldr elim [] + where elim e [] = [[e]] + elim e p@(n:ns) + | e == head n = (e:n):ns + | otherwise = [e]:p + +pack' (x:xs) = let (first,rest) = span (==x) xs + in (x:first) : pack' rest +pack' [] = [] + +pack'' (x:xs) = (x:takeWhile (==x) xs):(pack'' $ dropWhile (==x) xs) +pack'' [] = [] |