[Haskell-cafe] Splitting a list

Ronny Wichers Schreur ronny at cs.kun.nl
Thu Apr 22 10:47:42 EDT 2004

Steve Schafer writes (in the Haskell Cafe):

> I have a list of integers, e.g.:
>  [1,5,3,17,8,9]
> I want to split it into a pair of lists, with the criterion being that
> the sum of the elements in the first list is as large as possible, but
> not exceeding a threshold value. For example, if the threshold is 10,
> the result should be:
>  ([1,5,3],[17,8,9])
> and then I want to recursively apply this process to the remainder of
> the list, with the end result being a list of lists of integers. Using
> the same list along with a threshold of 18, I would get:
>  [[1,5,3],[17],[8,9]]

I would get

    [[1,5,3], [17], [8,9], [], [], [] ..]


Ronny Wichers Schreur

More information about the Haskell-Cafe mailing list