I have a list with L
elements.
I want to find an index within the list, that divides the list to two separate lists so the sum of elements in each of them are equal.
For example, in the list s = {3, 0, 2, 4, 5}
it is the 4th element:
Total[{3, 0, 2, 4}] == Total[{4, 5}]
I tried
Solve[Total[s[[1 ;; x]]] == Total[s[[x ;; -1]]], x]
but it fails with
Solve::nsmet: This system cannot be solved with the methods available to Solve.
L
might be high value, you could first use the fact that the desired sum isTotal[aList]/2
. Then create a loop that adds consecutive entries end stops whensum>desiredSum
, the loop index would be your desired index. This would also work when your problem does not have one and precise solution, i.e., if you deal with real numbers. Anyhow, this is more algorithmic rather than Mathematica comment. $\endgroup$