Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please use Haskell group_sum function takes two arguments where the first argument is a list (1st) and the second argument is an integer (n). The
Please use Haskell
group_sum function takes two arguments where the first argument is a list (1st) and the second argument is an integer (n). The goal is to produce a result in which the elements of the original list have been collected into ordered sub-lists each containing maximum number of consecutive elements from lst summing up to or less than n2k (where is k the group number starting at 0 , i.e., k=0,1,2,3,4.). The leftover elements (if there are any) are included in the last sub-list with a sum less than n2k. When elements are added to the groups, if the next element in the input list (13t) is greater than n2k, the group will be empty list [ ]. Examples: group_sum [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]10 [[1,2,3,4],[5,6,7],[8,9,10,11],[12,13,14,15,16],[17]] > group_sum [12,10,1,3,4,7,11,22,2,5,40,100,4]10 [[],[12],[10,1,3,4,7,11],[22,2,5,40],[100,4]] > group_sum [5,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,20]4 [[],[5,2,3,4,5,6],[7,8],[9,10,11],[12,13,14,15,16,20] > group_sum [] 3 []Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started