i have an array of numbers like this { 10, 5, 6, 9, 8, 11, 7, 4, 2, 13, 16, 1, 5 } I want split this array in several arrays in wich the sum of all element must be maximum 20. There is any snippet for doing this easily? Thanks

What rules govern the split? Are you looking for all permutations (possible ways) of making a total of 20 or less? Using the numbers in the initial array once or as many times as you like? e.g. {10,5}, {10,6}, {10,9} etc.

Not sure if this is what you're looking for but the following code takes each item in the array and looks ahead across the array for a second number that when added to it is less than or equal to 20:

If you're looking to see if you can take each number in turn and see if you can add one or more numbers from the rest of the array then that'll be a different solution.

Thanks, but the lenght of subarray can be more than 2. For this input: { 10, 5, 6, 9, 8, 11, 7, 4, 2, 13, 16, 1, 5 } I want this output {{10,5},{6,9},{8,11},{7, 4, 2},{13},{16,1},{5}}

You could probably do this using recursion assuming that your array of numbers doesn't get too long, and if you're worried about recursion then usually there's a way to replicate recursion using the fn!reduce function... but the logic would be something like this pseudocode:

inputs: A (set of solution arrays), B (current solution array that we are building), C (remaining numbers to process)