+ All Categories
Home > Documents > Assignment 6 for CISC

Assignment 6 for CISC

Date post: 23-Dec-2015
Category:
Upload: vil-leu
View: 26 times
Download: 8 times
Share this document with a friend
Description:
CISC Course work, assignment 6
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
Transcript
Page 1: Assignment 6 for CISC

Assignment 6: CISC 260 Winter 2014

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

2. Write a predicate called betterpath, where betterpath(pathi,path2,Better) meansthat Better is either pathi or Path2 and is the path with the greater total number ofpoints. If pathi and Path2 have the same total number of points, Better can be eitherone. Hint: the SWI-Prolog library contains a predicate called sum list, wheresum_iist (List, sum) means that if List is a list of numbers sum is the sum of all thenumbers 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. Ifthere 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 ahopscotch board. Then use bestpathofList to find the best path in that list of paths. (Idiscussed the setof predicate in class on Friday, March 21. For the large number of youwho weren't in class, you can wait for the video which will be posted on Saturday the22nd, or look up setof in your text.)

This is not the only way to solve the problem. Any hopscotch predicate that words correct forall our test cases will receive full marks. If you're having trouble, though, this is a suggestionfor breaking down the problem, and we will give partial credit if you can get some of thosehelper 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 thatworks correct with all of our test cases. If you didn't manage to get a working hopscotchpredicate, 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 instructionsin the Assignment Requirements page.

There are no style points for this assignment, but as always if you discipline yourself to writeclearly, 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

Page 2: Assignment 6 for CISC

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 iteasier for you to get help when you need it. If you follow a different scheme than the one Isuggested above and it's not all working, it's particularly important that you give a clearexplanation for what each of your helper predicates is supposed to do, so that we canevaluate each one separately.

Even though you won't earn style points for this assignment, the header comment at thebeginning of the program is a requirement. If you don't have a comment at the beginningidentifying yourself (by name, student number or NetID) and the other members of your groupif applicable, we will deduct an administrative penalty. Identifying yourself in the headercomment 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 theirbest paths. They apply to this assignment too. The TAs will be using different examples to testyour predicate, just to make sure that your functions aren't tailored specifically to theseexamples.

This page maintained by Margaret Lamb, Queen's University, Kingston, Ontario. Last modified 03/22/201402:34:29

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

Page 3: Assignment 6 for CISC

3/21/Z014 Assignment 6: CISC 260 Winter 2014

Assignment 6: Hopscotch In PrologCISC 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 29General questions about this assignment (administrative details, what is required, etc) shouldbe directed to the Assignment 6 Moodle forum. Please help your fellow students find Q&Aabout this assignment by using this designated forum rather than the general forum. Please donot post Prolog code or even pseudo-code on Moodle.

Please make sure you have read the general Assignment Requirements for CISC 260 beforebeginning this assignment. These detail all of the general administrative stuff you need toknow 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, inmy opinion). Second, you can pattern your solution after the Haskell solution I've posted onMoodle so you have a head start. And finally, I think it's a very useful experience to solve thesame problem in both languages. It helps you think about what ideas are common betweenthe two and what's different.

Instead of re-stating the basic problem, I'll refer you to the explanation given withAssignment 2.

In Prolog, what you must write is a predicate called hopscotch, wherehopscotch (squares, path) means that Path is the best legal path through a hopscotch board ifthe squares in the board contain the numbers of points in the list squares. By best path, Imean 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 thefirst parameter of hopscotch will be bound.

If your hopscotch predicate works without error, you will get full correctness points. If you'rehaving 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


Recommended