~cs538-1/public/handin/proj3/login
where login
is your login name.q1.pro,
q2a.pro, q2b.pro, q3.pro, q4a.pro, q4b.pro, q4c.pro, q4d.pro
. You can also include a file called README
with any notes about your submission. PLEASE NOTE: This is different
from previous project specifications.
Put all the files in the handin directory and do not make separate
subdirectories for each question. q2a.pro
in your solution for q2b.pro
), and
don't assume
that your code will execute in the handin folder. To achieve this, you
may need to make copies of code that is common to multiple sub-parts of
the same
question. Question | Required definitions | Sample usage (Prolog response underlined, semicolon and <Enter> indicate user asking Prolog to continue and stop searching for a solution, respectively) |
---|---|---|
1 | median(List,Median) |
Note that List will always be a
list with an odd number of distinct integers. ?- median([7,4,2,8,1,3,6],M). |
IMPORTANT: The assignment handout does not
mention this, but you should check that the inputs to setEq
are VALID SETS: they should not have repeated elements. Invalid sets
(lists with repeated elements) should always cause setEq
to fail.
|
||
2a | setEq(S1, S2) |
Note that you should test that a list is
a valid set, i.e., that it does not include duplicate elements. Invalid
sets should cause the set comparison to fail. ?- setEq([1,2,3],[2,1,3]). |
2b | setEq(S1, S2) |
Note that you should test that a list is
a valid set, i.e., that it does not include duplicate elements. Invalid
sets should cause the set comparison to fail. ?- setEq( [x,[1,2,3],y], [[2,1,3],y,x] ). |
3 | soln([D,E,M,N,O,R,S,Y]) |
Dots below indicate the single-digit unique
solutions found by your code. ?- soln([D,E,M,N,O,R,S,Y]). |
4a | subsets(S,PS) |
Note that the subsets need not be listed
exactly in the order shown. ?- subsets([1,2],PS). |
4b | subsets(S,PS) |
Note that 4b should also behave like 4a, as
the last input shows. ?- subsets([1],[[1],[]]). |
4c | subsets(S,PS) |
The variables used in the solution found by
Prolog don't matter as long as PS is the powerset of S (the order of
subsets is not important). Note that 4c should also behave like 4a and 4b, as the last inputs show. ?- subsets(S,PS). |
4d | subsets(S,PS) |
The order of elements in S may not be exactly
as shown below, but it should be the same set, and you should only
return one solution. Also note that 4d should also behave like 4a, 4b and 4c, as the last inputs show. ?- subsets(S,[[],[1],[2],[1,2]]). |
/s/std/bin/yap
).
You are free to work with your own version of Prolog which you might
have downloaded and installed at home but before submission,
you must make sure your code runs with our version of Prolog. If you
use Prolog library predicates, please make sure that these predicates
are also available in YAP Prolog installed here in CS. The first and foremost criteria for grading is correctness. Your programs should execute without errors and produce the correct output with our test suite. Points are awarded for each test input successfully handled by your code.
You can use any algorithms or Prolog predicates to produce the correct output, you are not restricted to following the exact path set by the questions.
No extra points for the most elegant programs but you are encouraged
to write
in a declarative style, making best use of Prolog's natural
abstractions:
declarative logic, backtracking, pattern matching and so on. These will
invariably reward you with compact, natural-looking code which
is easy to read and understand. Tell Prolog what you want, and not how
to
do it. See the lecture notes and look online for Prolog programs to get
a flavor of Prolog programming.
I may penalize programs that are excessively kludgy and hard to
read or
understand. Don't try to write C++ or Java in Prolog. In particular, the
excessive use of the extra-logical predicates and operators (the cut !
,
fail
, assert
, retract
and
their cousins) is frowned upon and will be penalized. Note that
this does not apply when the cut operator (!
) is required
or is natural for controlling backtracking, as with the subsets
predicate in Q.4.
Partial credit will be given for programs that seem to be on the
right track.