Without using cut write a predicate split3 that splits a lis

Without using cut, write a predicate split/3 that splits a list of integers into two lists: one containing the even ones, the other containing the odd ones.

For example: split([3,4,5,1,0,8,9],E,O)

should return:

E = [4,0,8]

O = [5,1,9].

Then try to improve the program, without changing its meaning, with the help of cut.

Solution

domains ls=integer* predicates split(ls,ls,ls) clauses split([],[],[]). split([X|L],[X|E],O):- if(X%2== 0) else split(L,E,O). split([X|L],E,[X|O):- split(L,E,O).
Without using cut, write a predicate split/3 that splits a list of integers into two lists: one containing the even ones, the other containing the odd ones. For

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site