HELP FOR ASSIGNMENT 4 PROBLEM 2 Problem 2 can be a little overwhelming if you don't know how to approach it. Therefore, this file was made so you can understand how to go about implementing it. First, read the understanding.prolog.txt file and the Prolog tutorial if you haven't already done so. Writing the taken.P file is the easy part. This file is supposed to contain the assertions of what classes you've already taken. Once Prolog reads this file, you should be able to query it by typing: taken(cs200). and Prolog should say "yes". So what should the file contain? That exact assertion, one for every class you've taken. HINT: This isn't as hard as you might think. If taken.P contains only one line (which is "taken(cs200).") then once Prolog loads taken.P, the query "taken(cs200)." will now return true. Writing the prereqs.P file is a little more involved. To begin with, you need to write assertions for every prerequisite that exists, just like you wrote an assertion for every class you've already taken in file taken.P . For example, since m160 is a prerequisite for m161, a line of your prereqs.P should be "prereq(m161,m160).". Remember, there are some statements that Prolog can't figure out with an algorithm (like the statement that m160 is a prereq for m161) so we must enter those statements in manually. You will also have to decide how to represent classes that have no prerequisites and make sure your rules work with that form. Now you have all the data needed to figure out if you "cantake" a class and what the "deficiencies" are (which is required for the homework). But how should you start? First, familiarize yourself with the setof operator. If you don't know how to use it, study this example: With these facts: loves(john,mary). loves(tim,mary). loves(miles,mary). loves(ed,susan). this query: setof(X, loves(X,mary), L). displays: L = [john,miles,tim] How would you use this operator to find a list of all the prerequisites for a certain class? Here are some additional guidelines and suggestions for writing prereqs.P. Your solution may not follow these. The only requirement is that you get the right responses as shown in the assignment. A) Remember how we went through a recursive example in class, the one where we wrote an ancestor functor using the parent functor to determine if someone was an ancestor of someone else? Write a similar functor, but make it work with prerequisites instead. B) Define a functor that is similar to the taken functor, but instead of taking a class as a parameter, it takes a list (of classes) as a parameter. In other words, calling this functor with the parameter [cs153,cs166,cs200] should display a "yes" because you have already taken all those classes. HINT: You might want to make this functor recursive (and with all recursive code, remember to include a base case). C) Make the functor cantake behave like the examples on the assignment. In other words, "cantake(cs440)." displays "yes" and "cantake(cs470)." displays "no". HINT: Find a list of prerequisites for a certain class and use the functor you defined in part B to find out if you've taken them all. D) Make the functor deficiencies behave like the examples on the assignment. Make this functor find the SET OF classes that have not been taken and are prerequisites (or prequisites for the prerequisites...) for the class you're querying. HINT: You might want to define additional functors to help with this. I hope this helps! -- Jean-Luc Romano