Bjorn Bringert wrote:
import Data.List
maxsubarrays xs = maximumBy (compare `on` sum)
[zs | ys <- inits xs, zs <- tails ys]
I love this solution: simple, understandable, elegant.
As a nit, I might take out the ys and zs names, which obscure the fact
that there is a hidden symmetry in the problem:
maxsubarrays xs = pickBest (return xs >>= inits >>= tails)
where pickBest = maximumBy (compare `on` sum)
-- NOTE: Since pickBest is invariant under permutation of its arg,
-- the order of inits and tails above may be reversed.
Dan Weston
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe