commit 8064dc247437f3ecd9b8cda573fa189d1c47e859 parent 3be4f8720a791167dcd859710a8566ac5021e9ab Author: Jared Tobin <jared@jtobin.ca> Date: Fri, 27 Feb 2015 22:20:36 +1300 Add forward diff exercise. Diffstat:
A | 20150120_forwarddiff/ForwardDifference.hs | | | 12 | ++++++++++++ |
1 file changed, 12 insertions(+), 0 deletions(-)
diff --git a/20150120_forwarddiff/ForwardDifference.hs b/20150120_forwarddiff/ForwardDifference.hs @@ -0,0 +1,12 @@ + +module ForwardDifference where + +leastForwardDifference :: (Ord a, Num a) => [a] -> Maybe a +leastForwardDifference xs = safeMaximum diffs where + diffs = zipWith (-) xs mins + mins = scanl1 min xs + +safeMaximum :: Ord a => [a] -> Maybe a +safeMaximum [] = Nothing +safeMaximum (x:xs) = Just $ foldr max x xs +