Last active
August 29, 2015 14:20
-
-
Save recursivecurry/c50410af188c95fcc60e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Ant where | |
import Data.List | |
group' :: [Int] -> [[Int]] | |
group' [] = [] | |
group' xs = foldr (\x acc -> if (head . head) acc == x then (x : (head acc)) : tail acc else [x]:acc) [[last xs]] (init xs) | |
concatMap' :: (a -> [b]) -> [a] -> [b] | |
concatMap' f xs = (concat . map f) xs | |
ant = iterate (concatMap (\g -> [head g, length g]) . group) [1] | |
ant2 = iterate (concatMap' (\g -> [head g, length g]) . group') [1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | The 'group' function takes a list and returns a list of lists such | |
-- that the concatenation of the result is equal to the argument. Moreover, | |
-- each sublist in the result contains only equal elements. For example, | |
-- | |
-- > group "Mississippi" = ["M","i","ss","i","ss","i","pp","i"] | |
-- | |
-- It is a special case of 'groupBy', which allows the programmer to supply | |
-- their own equality test. | |
group :: Eq a => [a] -> [[a]] | |
group = groupBy (==) | |
-- | The 'groupBy' function is the non-overloaded version of 'group'. | |
groupBy :: (a -> a -> Bool) -> [a] -> [[a]] | |
groupBy _ [] = [] | |
groupBy eq (x:xs) = (x:ys) : groupBy eq zs | |
where (ys,zs) = span (eq x) xs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment