I’d like to write one prolog statement to remove every even order element from a list
input: [a,b,c,d,e]
output: [a,c,e]
Can anyone help me out how can I write prolog statement for this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
here is my solution for your problem.
The problem is a trivial one, but if you want me to I’ll comment each line for you.
Here are the comments you requested:
First Line:
This line says if I somehow get to an empty list the result I should return is an empty list
Second Line: Here we say if a list consists of one element only (Head_ODD) then the resulting list should consist of that head only aswell
Third Line: If our list has 2 or more elements(Head_ODD,HEAD_EVEN + Tail) in the result list i should place only the HEAD_ODD , and try to solve the rest of the Tail recursivly