[Haskell-cafe] mapAccumL - find max in-sequence subsequence
jim burton
jim at sdf-eu.org
Sun Oct 29 06:11:23 EST 2006
Sebastian Sylvan-2 wrote:
>
> I'm not sure I completely understand what you want, and if it needs to
> be "cute" (i.e. some clever one liner usage of a library function).
> But here's my "get-the-job-done-solution" (assuming I understood what
> you want):
>
> import Data.List
> import Data.Ord
>
> longestInSequence :: (Enum a) => [a] -> Int
> longestInSequence = maximum . map (length . takeInSeq) . tails
>
> takeInSeq [] = []
> takeInSeq [x] = [x]
> takeInSeq (x:y:xs) | fromEnum (succ x) == fromEnum y = x : takeInSeq
> (y:xs)
> | otherwise = takeInSeq (x:xs)
>
> /S
>
Thanks, that's what I was looking for - and it doesn't need to be 'cute'!
--
View this message in context: http://www.nabble.com/mapAccumL---find-max-in-sequence-subsequence-tf2531704.html#a7059817
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
More information about the Haskell-Cafe
mailing list