Haskell Write Recursive Function Reachsum Takes Int Target Sum Positive List Positive Int Q37089894

In Haskell:

Write a recursive function reachSum that takes an Int as the targetsum, which will be positive, and
a list of positive Int values. You should return an Int (n) suchthat the sum of the first n elements is
less than or equal to the target, but the sum of the first n+1elements is greater than the target. If the
sum of the list overall is less than the target, return the numberof elements in the list. For example:
reachSum 40 [12, 27, 13, 10] -> 2
reachSum 100 [12, 27, 13, 10] -> 4
reachSum 10 [12, 27, 13, 10] -> 0


Solution


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.