Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Define and test the PROLOG predicates described below. Each of your predicates must have the same name and signature as the examples below . Your

Define and test the PROLOG predicates described below. Each of your predicates must have the same name and signature as the examples below. Your predicates must behave properly on all instances of valid input types. Please write in PROLOG.

3) Segregate

Define a predicate segregate/3 that takes a list of integers as an argument and

generates two lists, the first containing containing the even numbers from the original

list and the second sublist containing the odd numbers from the original list. Your

predicate should have the signature segregate(List, Even, Odd).

Examples:

?- segregate([8,7,6,5,4,3], Even, Odd).

Even = [8,6,4]

Odd = [7,5,3]

?- segregate([7,2,3,5,8], Even, Odd).

Even = [2,8]

Odd = [7,3,5]

?- segregate([-4,11,-7,9,0], Even, Odd).

Even = [-4,0]

Odd = [11,-7,9]

?- segregate([5,13,29], Even, Odd).

Even = []

Odd = [5,13,29]

?- segregate([], Even, Odd).

Even = []

Odd = []

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

More Books

Students also viewed these Databases questions

Question

Differentiate 3sin(9x+2x)

Answered: 1 week ago

Question

Compute the derivative f(x)=(x-a)(x-b)

Answered: 1 week ago