Permalink
Browse files

9' revised

  • Loading branch information...
1 parent c470562 commit ded40303069ff6c4b217d70d68a9baece057cccb @tianyicui committed Nov 17, 2010
Showing with 5 additions and 5 deletions.
  1. +2 −0 10.hs
  2. +3 −5 9.hs
View
2 10.hs
@@ -6,3 +6,5 @@ encode = foldr func []
func x ((n,y):sx)
| x == y = ((n+1, y):sx)
func x xs = ((1,x):xs)
+
+---- TODO: read http://www.haskell.org/haskellwiki/99_questions/Solutions/10
View
8 9.hs
@@ -9,11 +9,9 @@ pack [] = []
pack' :: (Eq a) => [a] -> [[a]]
pack' = foldr func []
- where
- func x [] = [[x]]
- func x (y:xs)
- | null y || x /= (head y) = ([x]:y:xs)
- | otherwise = ((x:y):xs)
+ where func x [] = [[x]]
+ func x (y:xs) =
+ if x == head y then (x:y):xs else [x]:y:xs
---- The use of `span`
pack'' (x:xs) =

0 comments on commit ded4030

Please sign in to comment.