SlideShare ist ein Scribd-Unternehmen logo
1 von 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).

Weitere ähnliche Inhalte

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

Arrays In General
Arrays In GeneralArrays In General
Arrays In General
martha leon
 
array-191103180006.pdf
array-191103180006.pdfarray-191103180006.pdf
array-191103180006.pdf
HEMAHEMS5
 

Ähnlich wie 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++
 

Mehr von 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.docx
patriciab30
 
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
patriciab30
 
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
patriciab30
 
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
patriciab30
 
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
patriciab30
 
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
patriciab30
 
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
patriciab30
 
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
patriciab30
 

Mehr von 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
 

Kürzlich hochgeladen

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 

Kürzlich hochgeladen (20)

UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 

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