Prolog program to spilt a list into a positive list numbers and a negative list numbers. Prolog program to remove the duplicate values from the list. Prolog program to find all the permutations of the elements of the list. Prolog program to find the maximum value of the list. Prolog program to find the minimum value of the list. Prolog program to find the sum of the values of the list. Prolog program that take two lists as input and produce a third list as output, this list is the sum of the two lists.
Labels: artificial intelligence , list programs , prolog programs. Tuesday, 27 May Prolog Program to replace a character with another character in the List. Prolog Program to replace a character with another character in the List. Prolog Program to reverse the List. Prolog Program to delete all the occurrences of an element from the List. Prolog Program to delete an element from the list. Older Posts Home. There are no cuts in the predicate definitions themselves.
The following is based on my previous answer to Remove duplicates in list Prolog ; the basic idea is, in turn, based on false's answer to Prolog union for A U B U C. If that bothers you, the code needs to be adapted. For the sake of completeness, here's how we could enforce that the intersection and the union are setsthat is lists that do not contain any duplicate elements.
With the new one they do. As the solution set size is infinite, none of these queries terminate universally. To cheat slightly less than my first answer, you could use the findall higher order predicate which gets Prolog to do the recursion for you :.
If the aim is to just 'get the job done', then swi prolog has built in primitives for exactly this purpose:. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Intersection and union of 2 lists Ask Question. Asked 9 years, 10 months ago. Active 1 year ago. Viewed 33k times. Keep in mind that i want to have just 1 result, not multiple results even if correct so running the code with this:?
Add a comment. Active Oldest Votes. I'll accept this answer as it is the most correct one. After deeper investigation i understood that what i asked is simply not possible without CUT, because of non-determinism. Python program to illustrate the intersection. Use of hybrid method. Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics. Previous Python Print all the common elements of two lists.
Next Python Union of two or more Lists. Recommended Articles. Python counter and dictionary intersection example Make a string using deletion and rearrangement. Article Contributed By :. Chinmoy Lenka.
0コメント