Assignment 6 For CISC

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Assignment 6: CISC 260 Winter 2014

a legal path through the hopscotch board containing the number of points in the list
Squares.

2. Write a predicate called betterpath, where betterpath(pathi,path2,Better) means


that Better is either pathi or Path2 and is the path with the greater total number of
points. If pathi and Path2 have the same total number of points, Better can be either
one. Hint: the SWI-Prolog library contains a predicate called sum list, where
sum_iist (List, sum) means that if List is a list of numbers sum is the sum of all the
numbers in the list.
3. Write a predicate called bestpathofList, where bestpathofList (ListofPaths,Path)
means that path is the path in Listof Paths with the greatest total number of points. If
there is a tie, you can resolve it however you like.
4. Use setof and your legaipath predicate to build a list of all the legal paths through a
hopscotch board. Then use bestpathofList to find the best path in that list of paths. (I
discussed the setof predicate in class on Friday, March 21. For the large number of you
who weren't in class, you can wait for the video which will be posted on Saturday the
22nd, or look up setof in your text.)
This is not the only way to solve the problem. Any hopscotch predicate that words correct for
all our test cases will receive full marks. If you're having trouble, though, this is a suggestion
for breaking down the problem, and we will give partial credit if you can get some of those
helper predicates working even if they don't all work.
Administrative Details:
To make it simpler for us to mark your assignments, you must put your hopscotch predicate,
plus helpers (if any) into a single file called Assignments.pi.
Marking Scheme:
This assignment will be marked out of 16 points. If you use the breakdown suggested above,
we will divide the points as follows:
legaipath: 4
betterPath: 4
bestPathOfList: 4

putting everything together to create a correct hopscotch predicate: 4


If you solve the problem a different way, you get all 16 points for a hopscotch predicate that
works correct with all of our test cases. If you didn't manage to get a working hopscotch
predicate, we'll give you partial credit according to how far you got.
Remember that we may deduct an administrative penalty if you do not follow the instructions
in the Assignment Requirements page.
There are no style points for this assignment, but as always if you discipline yourself to write
clearly, with meaningful names for your predicates and parameters -- and even include a few
http://research.cs.q ueensu.ca/home/cisc260/2014w/assig nments/assn6/assn6.html

21

3/21/2014

Assignment 6: CISC 260 Winter 2014

comments -- it will help you keep things straight and get your code working. It also makes it
easier for you to get help when you need it. If you follow a different scheme than the one I
suggested above and it's not all working, it's particularly important that you give a clear
explanation for what each of your helper predicates is supposed to do, so that we can
evaluate each one separately.
Even though you won't earn style points for this assignment, the header comment at the
beginning of the program is a requirement. If you don't have a comment at the beginning
identifying yourself (by name, student number or NetID) and the other members of your group
if applicable, we will deduct an administrative penalty. Identifying yourself in the header
comment is important to help us make sure that the right mark goes to the right person.

Some Examples: AssnZExamples.hs contains several examples of hopscotch boards and their
best paths. They apply to this assignment too. The TAs will be using different examples to tes
your predicate, just to make sure that your functions aren't tailored specifically to these
examples.
This page maintained by Margaret Lamb, Queen's University, Kingston, Ontario. Last modified 03/22/2014
02:34:29

http://research.cs.queensu.ca/home/cisc260/2014w/assignments/assn6/assn6.html

3/21/Z014

Assignment 6: CISC 260 Winter 2014

Assignment 6: Hopscotch In Prolog


CISC 260, Winter 2014
Queen's University, Kingston, Ontario
back to CISC 260 Moo die site

This Assignment is due by 8 a.m. on Saturday, March 29


General questions about this assignment (administrative details, what is required, etc) should
be directed to the Assignment 6 Moodle forum. Please help your fellow students find Q&A
about this assignment by using this designated forum rather than the general forum. Please do
not post Prolog code or even pseudo-code on Moodle.
Please make sure you have read the general Assignment Requirements for CISC 260 before
beginning this assignment. These detail all of the general administrative stuff you need to
know about assignments for this course, so I don't have to repeat them for each assignment.
For this assignment, you must solve the same Hopscotch puzzle as you did for Assignment 2,
but this time you must do it in Prolog. If you found Assignment 2 difficult, take a deep breath!
First, there are some aspects of Prolog that make this problem simpler to solve (at least, in
my opinion). Second, you can pattern your solution after the Haskell solution I've posted on
Moodle so you have a head start. And finally, I think it's a very useful experience to solve the
same problem in both languages. It helps you think about what ideas are common between
the two and what's different.
Instead of re-stating the basic problem, I'll refer you to the explanation given with
Assignment 2.
In Prolog, what you must write is a predicate called hopscotch, where
hopscotch (squares, path) means that Path is the best legal path through a hopscotch board if
the squares in the board contain the numbers of points in the list squares. By best path, I
mean the path with the largest total number of points. Here is an example using my solution:
I ?- hopscotch([7,4,5,9,6,1,2,3],Best).
Best = [7, 5, 6, 3] ;
false.

You don't have to indicate the total number of points, just the path. You may assume that the
first parameter of hopscotch will be bound.
If your hopscotch predicate works without error, you will get full correctness points. If you're
having trouble, though, here is a suggested strategy:

1. Write a predicate called legaipath, where legaipath (squares, Path) means that path is
http://research.cs.q ueensu.ca/home/cisc260/2014w/assig nments/assn6/assn6.html

1/3

You might also like