trying to write code that splits a list in half for even numbers of elements, eg. split([1,2,3,4],A,B)
would give A = [1,2]
and B = [3,4]
.
And behave like Java list.length()/2
would for odd numbers of elements, so split([1,2,3,4,5],A,B)
would give A = [1,2]
and B = [3,4,5]
.
The closest I can get is something like this, but this isn't quite right, and only works for even numbers.
split(L, A, B) :-
append(A, B, L),
length(A, N),
length(B, N).