SlideShare a Scribd company logo
1 of 2
I'm using SWI-Prolog for the project.
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 = []
Solution
segregate/3:
segregate ([ ], [ ], [ ]).
segregate ([H|T], [H|X],Odd) :- 0 is H mod 2, !, segregate (T,X,Odd).
segregate ([H|T],Even,[H|Y]) :- segregate (T,Even,Y).

More Related Content

Similar to I-'m using SWI-Prolog for the project- Define a predicate segregate-3.docx

Similar to I-'m using SWI-Prolog for the project- Define a predicate segregate-3.docx (20)

Lecture 6 - Arrays
Lecture 6 - ArraysLecture 6 - Arrays
Lecture 6 - Arrays
 
Sets in python
Sets in pythonSets in python
Sets in python
 
Arrays In General
Arrays In GeneralArrays In General
Arrays In General
 
Array
ArrayArray
Array
 
Introduction to Array & Structure & Basic Algorithms.pptx
Introduction to Array & Structure & Basic Algorithms.pptxIntroduction to Array & Structure & Basic Algorithms.pptx
Introduction to Array & Structure & Basic Algorithms.pptx
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
 
array-191103180006.pdf
array-191103180006.pdfarray-191103180006.pdf
array-191103180006.pdf
 
Lecture 6
Lecture 6Lecture 6
Lecture 6
 
TDD with Elm
TDD with ElmTDD with Elm
TDD with Elm
 
Shell sorting
Shell sortingShell sorting
Shell sorting
 
Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303
 
Arrays
ArraysArrays
Arrays
 
Chap 6 c++
Chap 6 c++Chap 6 c++
Chap 6 c++
 
Introducing R
Introducing RIntroducing R
Introducing R
 
Arrays Java
Arrays JavaArrays Java
Arrays Java
 
Python Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionaryPython Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, Dictionary
 
C Language Lecture 11
C Language Lecture  11C Language Lecture  11
C Language Lecture 11
 
2D-Array
2D-Array 2D-Array
2D-Array
 
Compiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term RewritingCompiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term Rewriting
 
Chap 6 c++
Chap 6 c++Chap 6 c++
Chap 6 c++
 

More from patriciab30

ID-D Samei- -14- Which ofthe following should sever be evaporwedon-hpl.docx
ID-D Samei- -14- Which ofthe following should sever be evaporwedon-hpl.docxID-D Samei- -14- Which ofthe following should sever be evaporwedon-hpl.docx
ID-D Samei- -14- Which ofthe following should sever be evaporwedon-hpl.docxpatriciab30
 
I- Physical Properties- Color-- Clear Odor- Nail polish Yemover (corre.docx
I- Physical Properties- Color-- Clear Odor- Nail polish Yemover (corre.docxI- Physical Properties- Color-- Clear Odor- Nail polish Yemover (corre.docx
I- Physical Properties- Color-- Clear Odor- Nail polish Yemover (corre.docxpatriciab30
 
I- H low do you know when to name something as an ionic compound- 2- H.docx
I- H low do you know when to name something as an ionic compound- 2- H.docxI- H low do you know when to name something as an ionic compound- 2- H.docx
I- H low do you know when to name something as an ionic compound- 2- H.docxpatriciab30
 
I- Which type of star oscillates in brightness in a pattern in such a.docx
I- Which type of star oscillates in brightness in a pattern in such a.docxI- Which type of star oscillates in brightness in a pattern in such a.docx
I- Which type of star oscillates in brightness in a pattern in such a.docxpatriciab30
 
I- Describe the different bonds that exist between the different macro.docx
I- Describe the different bonds that exist between the different macro.docxI- Describe the different bonds that exist between the different macro.docx
I- Describe the different bonds that exist between the different macro.docxpatriciab30
 
I- Anole Company 25 POINTS Anole Company was incorporated as a new bus.docx
I- Anole Company 25 POINTS Anole Company was incorporated as a new bus.docxI- Anole Company 25 POINTS Anole Company was incorporated as a new bus.docx
I- Anole Company 25 POINTS Anole Company was incorporated as a new bus.docxpatriciab30
 
I) What are secondary bonding interactions (also called charge transfe.docx
I) What are secondary bonding interactions (also called charge transfe.docxI) What are secondary bonding interactions (also called charge transfe.docx
I) What are secondary bonding interactions (also called charge transfe.docxpatriciab30
 
I need to write a soil chemistry paper using scientific articles and j.docx
I need to write a soil chemistry paper using scientific articles and j.docxI need to write a soil chemistry paper using scientific articles and j.docx
I need to write a soil chemistry paper using scientific articles and j.docxpatriciab30
 
I need help with CH4- What is its intermolecular force- Question 4 of.docx
I need help with CH4- What is its intermolecular force- Question 4 of.docxI need help with CH4- What is its intermolecular force- Question 4 of.docx
I need help with CH4- What is its intermolecular force- Question 4 of.docxpatriciab30
 
I need help writing this program in MIPS MARS assembly language 2- Mak.docx
I need help writing this program in MIPS MARS assembly language 2- Mak.docxI need help writing this program in MIPS MARS assembly language 2- Mak.docx
I need help writing this program in MIPS MARS assembly language 2- Mak.docxpatriciab30
 
I need help writing a python 3 function- I need to write a function th.docx
I need help writing a python 3 function- I need to write a function th.docxI need help writing a python 3 function- I need to write a function th.docx
I need help writing a python 3 function- I need to write a function th.docxpatriciab30
 
I need help with my geotechnical engineering HW-- Can a soil have a lo.docx
I need help with my geotechnical engineering HW-- Can a soil have a lo.docxI need help with my geotechnical engineering HW-- Can a soil have a lo.docx
I need help with my geotechnical engineering HW-- Can a soil have a lo.docxpatriciab30
 
I need help m5 In the modern Respond to the following questions with s.docx
I need help m5 In the modern Respond to the following questions with s.docxI need help m5 In the modern Respond to the following questions with s.docx
I need help m5 In the modern Respond to the following questions with s.docxpatriciab30
 
I need help describing the two kinds of people who are responsible for.docx
I need help describing the two kinds of people who are responsible for.docxI need help describing the two kinds of people who are responsible for.docx
I need help describing the two kinds of people who are responsible for.docxpatriciab30
 
12- Your friend has high protein and sugar in her urine- She repeats t.docx
12- Your friend has high protein and sugar in her urine- She repeats t.docx12- Your friend has high protein and sugar in her urine- She repeats t.docx
12- Your friend has high protein and sugar in her urine- She repeats t.docxpatriciab30
 
12- Under which of the following circumstances is the principal-agent.docx
12- Under which of the following circumstances is the principal-agent.docx12- Under which of the following circumstances is the principal-agent.docx
12- Under which of the following circumstances is the principal-agent.docxpatriciab30
 
12- An Asteroid passes by Earth every 17 years- The asteroid orbits th.docx
12- An Asteroid passes by Earth every 17 years- The asteroid orbits th.docx12- An Asteroid passes by Earth every 17 years- The asteroid orbits th.docx
12- An Asteroid passes by Earth every 17 years- The asteroid orbits th.docxpatriciab30
 
11- What are the components of the user interface-SolutionNow a days t.docx
11- What are the components of the user interface-SolutionNow a days t.docx11- What are the components of the user interface-SolutionNow a days t.docx
11- What are the components of the user interface-SolutionNow a days t.docxpatriciab30
 
11- The employer payroll tax expense on employee wages that is paid fo.docx
11- The employer payroll tax expense on employee wages that is paid fo.docx11- The employer payroll tax expense on employee wages that is paid fo.docx
11- The employer payroll tax expense on employee wages that is paid fo.docxpatriciab30
 
110) When you create a form from two tables that have a one-to-many re.docx
110) When you create a form from two tables that have a one-to-many re.docx110) When you create a form from two tables that have a one-to-many re.docx
110) When you create a form from two tables that have a one-to-many re.docxpatriciab30
 

More from patriciab30 (20)

ID-D Samei- -14- Which ofthe following should sever be evaporwedon-hpl.docx
ID-D Samei- -14- Which ofthe following should sever be evaporwedon-hpl.docxID-D Samei- -14- Which ofthe following should sever be evaporwedon-hpl.docx
ID-D Samei- -14- Which ofthe following should sever be evaporwedon-hpl.docx
 
I- Physical Properties- Color-- Clear Odor- Nail polish Yemover (corre.docx
I- Physical Properties- Color-- Clear Odor- Nail polish Yemover (corre.docxI- Physical Properties- Color-- Clear Odor- Nail polish Yemover (corre.docx
I- Physical Properties- Color-- Clear Odor- Nail polish Yemover (corre.docx
 
I- H low do you know when to name something as an ionic compound- 2- H.docx
I- H low do you know when to name something as an ionic compound- 2- H.docxI- H low do you know when to name something as an ionic compound- 2- H.docx
I- H low do you know when to name something as an ionic compound- 2- H.docx
 
I- Which type of star oscillates in brightness in a pattern in such a.docx
I- Which type of star oscillates in brightness in a pattern in such a.docxI- Which type of star oscillates in brightness in a pattern in such a.docx
I- Which type of star oscillates in brightness in a pattern in such a.docx
 
I- Describe the different bonds that exist between the different macro.docx
I- Describe the different bonds that exist between the different macro.docxI- Describe the different bonds that exist between the different macro.docx
I- Describe the different bonds that exist between the different macro.docx
 
I- Anole Company 25 POINTS Anole Company was incorporated as a new bus.docx
I- Anole Company 25 POINTS Anole Company was incorporated as a new bus.docxI- Anole Company 25 POINTS Anole Company was incorporated as a new bus.docx
I- Anole Company 25 POINTS Anole Company was incorporated as a new bus.docx
 
I) What are secondary bonding interactions (also called charge transfe.docx
I) What are secondary bonding interactions (also called charge transfe.docxI) What are secondary bonding interactions (also called charge transfe.docx
I) What are secondary bonding interactions (also called charge transfe.docx
 
I need to write a soil chemistry paper using scientific articles and j.docx
I need to write a soil chemistry paper using scientific articles and j.docxI need to write a soil chemistry paper using scientific articles and j.docx
I need to write a soil chemistry paper using scientific articles and j.docx
 
I need help with CH4- What is its intermolecular force- Question 4 of.docx
I need help with CH4- What is its intermolecular force- Question 4 of.docxI need help with CH4- What is its intermolecular force- Question 4 of.docx
I need help with CH4- What is its intermolecular force- Question 4 of.docx
 
I need help writing this program in MIPS MARS assembly language 2- Mak.docx
I need help writing this program in MIPS MARS assembly language 2- Mak.docxI need help writing this program in MIPS MARS assembly language 2- Mak.docx
I need help writing this program in MIPS MARS assembly language 2- Mak.docx
 
I need help writing a python 3 function- I need to write a function th.docx
I need help writing a python 3 function- I need to write a function th.docxI need help writing a python 3 function- I need to write a function th.docx
I need help writing a python 3 function- I need to write a function th.docx
 
I need help with my geotechnical engineering HW-- Can a soil have a lo.docx
I need help with my geotechnical engineering HW-- Can a soil have a lo.docxI need help with my geotechnical engineering HW-- Can a soil have a lo.docx
I need help with my geotechnical engineering HW-- Can a soil have a lo.docx
 
I need help m5 In the modern Respond to the following questions with s.docx
I need help m5 In the modern Respond to the following questions with s.docxI need help m5 In the modern Respond to the following questions with s.docx
I need help m5 In the modern Respond to the following questions with s.docx
 
I need help describing the two kinds of people who are responsible for.docx
I need help describing the two kinds of people who are responsible for.docxI need help describing the two kinds of people who are responsible for.docx
I need help describing the two kinds of people who are responsible for.docx
 
12- Your friend has high protein and sugar in her urine- She repeats t.docx
12- Your friend has high protein and sugar in her urine- She repeats t.docx12- Your friend has high protein and sugar in her urine- She repeats t.docx
12- Your friend has high protein and sugar in her urine- She repeats t.docx
 
12- Under which of the following circumstances is the principal-agent.docx
12- Under which of the following circumstances is the principal-agent.docx12- Under which of the following circumstances is the principal-agent.docx
12- Under which of the following circumstances is the principal-agent.docx
 
12- An Asteroid passes by Earth every 17 years- The asteroid orbits th.docx
12- An Asteroid passes by Earth every 17 years- The asteroid orbits th.docx12- An Asteroid passes by Earth every 17 years- The asteroid orbits th.docx
12- An Asteroid passes by Earth every 17 years- The asteroid orbits th.docx
 
11- What are the components of the user interface-SolutionNow a days t.docx
11- What are the components of the user interface-SolutionNow a days t.docx11- What are the components of the user interface-SolutionNow a days t.docx
11- What are the components of the user interface-SolutionNow a days t.docx
 
11- The employer payroll tax expense on employee wages that is paid fo.docx
11- The employer payroll tax expense on employee wages that is paid fo.docx11- The employer payroll tax expense on employee wages that is paid fo.docx
11- The employer payroll tax expense on employee wages that is paid fo.docx
 
110) When you create a form from two tables that have a one-to-many re.docx
110) When you create a form from two tables that have a one-to-many re.docx110) When you create a form from two tables that have a one-to-many re.docx
110) When you create a form from two tables that have a one-to-many re.docx
 

Recently uploaded

Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Mohamed Rizk Khodair
 
size separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticssize separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticspragatimahajan3
 
How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17Celine George
 
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
 Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatmentsaipooja36
 
factors influencing drug absorption-final-2.pptx
factors influencing drug absorption-final-2.pptxfactors influencing drug absorption-final-2.pptx
factors influencing drug absorption-final-2.pptxSanjay Shekar
 
ppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyesppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyesashishpaul799
 
REPRODUCTIVE TOXICITY STUDIE OF MALE AND FEMALEpptx
REPRODUCTIVE TOXICITY  STUDIE OF MALE AND FEMALEpptxREPRODUCTIVE TOXICITY  STUDIE OF MALE AND FEMALEpptx
REPRODUCTIVE TOXICITY STUDIE OF MALE AND FEMALEpptxmanishaJyala2
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...Nguyen Thanh Tu Collection
 
An Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptxAn Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptxCeline George
 
IATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdffIATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdff17thcssbs2
 
How to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 InventoryHow to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 InventoryCeline George
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfbu07226
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismDabee Kamal
 
....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdf....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdfVikramadityaRaj
 
Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Celine George
 
philosophy and it's principles based on the life
philosophy and it's principles based on the lifephilosophy and it's principles based on the life
philosophy and it's principles based on the lifeNitinDeodare
 
Post Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdf
Post Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdfPost Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdf
Post Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdfPragya - UEM Kolkata Quiz Club
 
Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024CapitolTechU
 
Essential Safety precautions during monsoon season
Essential Safety precautions during monsoon seasonEssential Safety precautions during monsoon season
Essential Safety precautions during monsoon seasonMayur Khatri
 

Recently uploaded (20)

Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).
 
Post Exam Fun(da) Intra UEM General Quiz - Finals.pdf
Post Exam Fun(da) Intra UEM General Quiz - Finals.pdfPost Exam Fun(da) Intra UEM General Quiz - Finals.pdf
Post Exam Fun(da) Intra UEM General Quiz - Finals.pdf
 
size separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticssize separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceutics
 
How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17
 
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
 Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
 
factors influencing drug absorption-final-2.pptx
factors influencing drug absorption-final-2.pptxfactors influencing drug absorption-final-2.pptx
factors influencing drug absorption-final-2.pptx
 
ppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyesppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyes
 
REPRODUCTIVE TOXICITY STUDIE OF MALE AND FEMALEpptx
REPRODUCTIVE TOXICITY  STUDIE OF MALE AND FEMALEpptxREPRODUCTIVE TOXICITY  STUDIE OF MALE AND FEMALEpptx
REPRODUCTIVE TOXICITY STUDIE OF MALE AND FEMALEpptx
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
 
An Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptxAn Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptx
 
IATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdffIATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdff
 
How to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 InventoryHow to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 Inventory
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdf....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdf
 
Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17
 
philosophy and it's principles based on the life
philosophy and it's principles based on the lifephilosophy and it's principles based on the life
philosophy and it's principles based on the life
 
Post Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdf
Post Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdfPost Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdf
Post Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdf
 
Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024
 
Essential Safety precautions during monsoon season
Essential Safety precautions during monsoon seasonEssential Safety precautions during monsoon season
Essential Safety precautions during monsoon season
 

I-'m using SWI-Prolog for the project- Define a predicate segregate-3.docx

  • 1. I'm using SWI-Prolog for the project. 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 = [] Solution segregate/3:
  • 2. segregate ([ ], [ ], [ ]). segregate ([H|T], [H|X],Odd) :- 0 is H mod 2, !, segregate (T,X,Odd). segregate ([H|T],Even,[H|Y]) :- segregate (T,Even,Y).