![]() |
.. (לתיקייה המכילה) | |
Q1: When we need to return a list representing a result set, are we expected to return a specific list? | |
You can return any list that represent the result set. It doesn't matter which one you choose to return. For example: Applying my_union([1,2,2,3,4,3], [2,1,2,1,1,1], L) can return any list that represents the set [1,2,3,4]. |
Q1: May we assume that the first argument of 'equals' is never a variable? | |
Yes, please do. Otherwise some implementations won't work. |
Q2: I wrote the rule 'at_place' and it works fine, but when I insert ';' after ( at_place(b,3,Y). ) the program turn into inf. loop. | |
You may ignore it. |
Q3: What should be returned when X,Y are the same? | |
If X=Y=a (for example), You should return the path [a] with cost 0. |
Q1: May we also assume that the first parameter in contains and truly_contains is also not a variable? | |
Yes, you may. |
Q2d: In separate(Numbers, Positives, Negatives) may we assume 'Numbers' is not a variable? | |
Yes, you may. |
General: How should the examples file look like? | |
It should be a text file of the input-output session in prolog. Since extracting the text can be an annoying issue you are allowed not to submit the examples with the wet part, and to attach a print-screen output to the dry part. (If you print-screen the 'plcon.exe' session, you can apply 'negative' (with an image editing software), and get a nice black on white output. Otherwise use 'plwin.exe'). |
Question1: How can we handle cases where different lists can represent the same set? | |
Rearranging the inputs is not a good solution. You should think of using 'equals' for example, to handle all cases of equivalent lists that represent the same set. |
Q3.3: Can you explain how we can get all the answers in a list. | |
The idea is to implement a predict that accumulates all possible answers using assert&retract. Use retract to extract the list you have accumulated so far, and use assert to save it again with the current solution. Think about how to make the rule fail so all solutions of solve2 are tried. |
Q1, my_union: is the list return supposed to have only one copy of each item? or is it like any other group defined, in which duplicates are acceptable? (question also applies to the rest of the predicates) | |
Duplicates are acceptable. Also make sure the predicates works the other way with different representations of the sets, E,g: All should return 'yes': my_union([1,2,3],[1,1,1,4,2],[1,2,4,4,3]). my_union([1,1,2],[5],[5,2,1,1]). ... |
Q3a: You wrote in the example that semicolon after the solution should return "no", but in the example there was also only one route possible, if we have a few possible routes, should the semicolon return the rest of the possible routes? or just "no" after the first possible one? | |
It should return all possible routes. |
General: When I load my examples file into the Prolog consult, a line such as this: | |
Prolog thinks you had defined a new rule: rotate([1,4,7,8,4],3,X). which is equivalent to the rule: rotate([1,4,7,8,4],3,_). so it tells you X is not relevant and can be changed to a wildcard. There's no way that I know of to load a command file.You have to input the examples manually and submit a file that represents the input-output session you had made. |