Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- consume :: (Ord a, Num a) => [a] -> a -> a -> a -> a
- consume [] _ _ sum = sum
- consume xs lh rh sum =
- if lh <= rh then
- consume (tail xs) (max lh next_l) rh (if next_l >= lh then sum else sum + lh - next_l) else
- consume (init xs) lh (max rh next_r) (if next_r >= rh then sum else sum + rh - next_r)
- where next_l = head xs
- next_r = last xs
- calculatePuddleCapacity :: (Num p, Ord p) => [p] -> p
- calculatePuddleCapacity xs = if length xs <= 2 then 0 else consume (init $ tail xs) (head xs) (last xs) 0
- main :: IO ()
- main = do
- putStrLn . show $ calculatePuddleCapacity [2, 1, 2]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement