Personal tools

Haskell Quiz/Maximum Sub-Array/Solution Jkramar

From HaskellWiki

< Haskell Quiz | Maximum Sub-Array(Difference between revisions)
Jump to: navigation, search
 
m

Revision as of 20:01, 19 November 2008


maxSubArray xs = drop from$take to xs where
  sumswithpos = zip (scanl (+) 0 xs) [0..]
  diff ((a,ai),(b,bi)) = (a-b,(bi,ai))
  (from,to) = snd$maximum$map diff$zip sumswithpos$scanl1 min sumswithpos