Menu

[Solved]4 3 Points Write Function Reachsum Takes Int Target Sum Positive List Positive Int Values Q37184975

In Haskell: functions must be recursively4. (3 points) Write a function reachSum that takes an Int as the target sum, which will be positive, and a list of positive I

4. (3 points) Write a function reachSum that takes an Int as the target sum, which will be positive, and a list of positive Int values. You should return an Int (n) such that the sum of the first n elements is less than or equal to the target, but the sum of the first n+1 elements is greater than the target. If the sum of the list overall is less than the target, return the number of 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 Show transcribed image text 4. (3 points) Write a function reachSum that takes an Int as the target sum, which will be positive, and a list of positive Int values. You should return an Int (n) such that the sum of the first n elements is less than or equal to the target, but the sum of the first n+1 elements is greater than the target. If the sum of the list overall is less than the target, return the number of 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

Expert Answer


Answer to 4. (3 points) Write a function reachSum that takes an Int as the target sum, which will be positive, and a list of posit… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *