Skip to content

Commit

Permalink
9' revised
Browse files Browse the repository at this point in the history
  • Loading branch information
tianyicui committed Nov 17, 2010
1 parent c470562 commit ded4030
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 2 additions & 0 deletions 10.hs
Expand Up @@ -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
8 changes: 3 additions & 5 deletions 9.hs
Expand Up @@ -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) =
Expand Down

0 comments on commit ded4030

Please sign in to comment.