Given a list of positive integers, partition the list into two sublists such that the absolute value of the difference of the sums over the two sublists is minimal.
The output of the program should be the (non-negative) difference of these sums.
Examples:
[1,2,3] -> 0 # [1,2], [3]
[2,3,5,7,11] -> 0 # [2,5,7], [3,11]
[13,17,19,23] -> 0 # [13,23], [17,19]
[1,2,3,4] -> 0 # [1,4], [2,3]
[2,2,2,3,3] -> 0 # [2,2,2], [3,3]
[1,2,3,4,5] -> 1 # [1,2,4], [3,5]
[1,2,3,4,5,6] -> 1 # [1,2,3,4], [5,6]
[1,1,2,5] -> 1 # [1,1,2], [5]
[1,3,9,27] -> 14 # [1,3,9], [27]
Rules
- The sublists do not need to be contiguous
- Every element of the list has to be in (exactly) one of the two sublists
- The list can contain duplicate elements
- You can assume that the list contains at least 3 elements
- You are allowed to assume that the list is sorted (using any convenient ordering)
- The ordering of two numbers should be the same for all lists
- This is code-golf the shortest solution wins
[2,2,2,3,3] -> 0
\$\endgroup\$