Question

Write a program in prolog to delete all reference of a particular item from a list....

Write a program in prolog to delete all reference of a particular item from a list. It should have three arguments. The list you wish to use, the item to delete, and the resulting list. Here are some example of it behaviour

?- delete_all([a,b,a,c,a,d],a,Result).

Result = [b,c,d]

? - delete_all([a,b,a,c,a,d],b,Result).

Result = [a,a,c,a,d]

Homework Answers

Answer #1

delete_all([],_,[]):-!.   %If list is empty then Resultant list is also empty
delete_all([Elem|T],Elem,R):- delete_all(T,Elem,R).   %If Head of the list is same as Element to be deleted, Remove It
delete_all([H|T],Elem,[H|R]):-H \= Elem, delete_all(T,Elem,R).   %move ahead

/* OUTPUT */

/* please upvote */

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a Prolog program called replace that replaces all occurrences of one item in a list...
Write a Prolog program called replace that replaces all occurrences of one item in a list with a new item. Example under: ?- replace([apple,butter,apple,candy,apple,potato],apple,milk,Result). Result = [milk,butter,milk,candy,milk,potato]
Write a program in Java that: 1. will prompt user with a menu that contains options...
Write a program in Java that: 1. will prompt user with a menu that contains options to: a. Add a To-Do Item to a todo list. A To-Do Item contains: i. An arbitrary reference number (4; 44,004; etc.) ii. A text description of the item ("Pick up dry cleaning", etc.) iii. A priority level (1, 2, 3, 4, or 5) b. View an item in the list (based on its reference number) c. Delete an item from the list (based...
Machine Problem 3 - Linked List C++ For this assignment you will write a program that...
Machine Problem 3 - Linked List C++ For this assignment you will write a program that inserts 20 random integers from 0 to 100 in order in a linked list object. The program will create another linked list, but with 15 random integers from 0 – 100 in order. The program then will merge those two ordered linked list into a single ordered list. The function merge should receive references to each of the list objects to be merged and...
Question1: Write a Python Program that asks for the grades of 5 quizzes and then prints...
Question1: Write a Python Program that asks for the grades of 5 quizzes and then prints the highest grade. [6 Marks] Question2: Write a Python Program that does the following tasks. [8 Marks] Create an empty list Ask the user for 5 positive numbers and append them to the list Find and print the sum of all the numbers in the list Delete the last element from the list and then print the list Question3: Consider you have the following...
Prime Numbers) Write a program to calculate and print a list of all prime numbers from...
Prime Numbers) Write a program to calculate and print a list of all prime numbers from 1 to 100. C programming
Color. Write a program that displays the color of the camera whose item number is entered...
Color. Write a program that displays the color of the camera whose item number is entered by the user. All item numbers contain exactly seven characters. All items are available in four colors: black, green, red, and white. The fourth character in the item number indicates the item’s color, as follows: a B or b indicates Black, a G or g indicates Green, an R or r indicates Red, and a W or w indicates White. If the item number...
Write a program that will read the information from a file into a list and then...
Write a program that will read the information from a file into a list and then display the list to the screen. Remove the fifth item in the list and display the list again. Ask the program user for an entry into the list and add it to the list. Display the list one last time. disneyin.txt file daisy   123 donald   345 goofy   654 mickey   593 minnie   489 daffy   432 pluto   765 huey   321 dewey   987 lewey   554 porky   333...
Create a program that filters the data in a CSV file of product data based on...
Create a program that filters the data in a CSV file of product data based on some search word and prints the resulting output to a new file. Additionally, the program will print the number of items filtered to stdout. • Your program should take three arguments: an input file to process, an output file to save the results, and a search word. • If the output file already exists or cannot be opened, warn the user by printing "CANNOT...
1. Write a program to: Prompt the user to input an integer, a double, a character,...
1. Write a program to: Prompt the user to input an integer, a double, a character, and a string, storing each into separate variables. Then, output those four values on a single line separated by a space. Add a statement to also output in reverse. Add a statement to cast the double to an integer, and output that integer. 2. 2. Choose the statement(s) that generate(s) this output: I wish you were here a. printf("I wish", "you were here"); b....
Write a Java program to print the result of the following operations. Your program should contain...
Write a Java program to print the result of the following operations. Your program should contain 4 methods (for each of given data sets). Yes, methods here are not structurally necessary, this requirement is only for you to get practice writing methods. Test Data: a. -8 + 4.0 * 6 b. (11+9) % 9 c. 20 + (-3)*3.0 / 8 d. 5 + 14 / 3 * 2 - 7 % 3 Your program:
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT