aish 1352
aish 1352

Reputation: 1

I Want to seperate odd and even numbers in a list and print the original list along with the even and odd list

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).

enter image description here

i want to print the original list along with the even and odd numbers list

Upvotes: 0

Views: 48

Answers (1)

Nicholas Carey
Nicholas Carey

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

Related Questions