The Question:
Define a predicate split/4 which, when provided with a list L and integer N returns two lists, A and B, where A contains the items in L that are greater than or equal to N and B contains the items that are lower than N.
Sample query with expected result:
?- split([1, 5, 2, 3, 4], 3, A, B).
A = [5, 3, 4],
B = [1, 2].
My code:
spit([], 0, [], []).
split([I|Is], N, [A|As], [_B|Bs]):-
I >= N,
A is I,
split(Is, N, As, Bs).
split([I|Is], N, [_A|As], [B|Bs]):-
I < N,
B is I,
split(Is, N, As, Bs).
Rather than producing A
and B
as required, my code simply returns false
. I'm not sure why.