[ create a new paste ] login | about

Link: http://codepad.org/QollsjCw    [ raw code | output | fork ]

Haskell, pasted on Mar 18:
-- $setup
-- >>> import Control.Applicative ((<*>))
-- >>> import Data.List (isInfixOf)
-- >>> import Test.QuickCheck

-- Level: Easy
-- Pointfree: yes


-- | mostRepeatedElem
-- Returns the element with the longest (consecutive) repetition and the
-- repetition number
-- If there are tie, the last most repeated element is returned
-- It returns error on empty string
-- 
-- Examples:
--
-- >>> mostRepeatedElem "hello world!"
-- ('l',2)
--
-- >>> mostRepeatedElem [1,1,2,2]
-- (2,2)
--
-- prop> (flip isInfixOf <*> uncurry (flip replicate) . mostRepeatedElem) . getNonEmpty

mostRepeatedElem :: Eq a => [a] -> (a,Int)
mostRepeatedElem = undefined


Output:
1
2
Error occurred
ERROR - Undefined variable "main"


Create a new paste based on this one


Comments: