Reputation: 1
i am able to separate the even and odd from the list but unable to print the original list
even_odd([], [], []).
even_odd([X|Xs], [X|Even], Odd) :- 0 is X mod 2,even_odd(Xs, Even, Odd).
even_odd([X|Xs], Even, [X|Odd]) :- 1 is X mod 2,even_odd(Xs, Even, Odd).
i want to print the original list along with the even and odd numbers list
Upvotes: 0
Views: 48
Reputation: 74187
Why not just say:
?- Ns = [0,1,2,3,4,5,6,7,8,9], even_odd(Ns,Es,Os) .
That should give you:
Ns = [0,1,2,3,4,5,6,7,8,9],
Es = [0,2,4,6,8],
Os = [1,3,5,7,9]
Upvotes: 1