pset8 - MIT OpenCourseWare http:/ocw.mit.edu 6.00...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
MIT OpenCourseWare http://ocw.mit.edu 6.00 Introduction to Computer Science and Programming Fall 2008 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms .
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6.00: Introduction to Computer Science and Programming Problem Set 8: Dynamic Programming Handed out : Tuesday, October 21, 2008 Due : Thursday, October 30, 2008 Introduction At an institute of higher education that shall be nameless, it used to be the case that a human advisor would help each student formulate a list of subjects that would meet the student’s objectives. However, because of financial troubles, the Institute has decided to replace human advisors with software. Given the amount of work a student wants to do, the program returns a list of subjects that maximizes the amount of value. The goal of this problem set is to implement a dynamic programming algorithm and learn how to pass functions as arguments. Workload Please let us know how long you spend on each problem. We want to be careful not to overload you by giving out problems that take longer than we anticipated. Collaboration You may work with other students. However, each student should write up and hand in his or her assignment separately. Be sure to indicate with whom you have worked. For further details, please review the collaboration policy as stated in the syllabus. Getting Started Download and save these files into the same folder. ps8.py: the skeleton you’ll fill in for Problems 1–5 subjects.txt: the list of subjects with value and work information. Problem 1: Building A Subject Dictionary The first step is to implement loadSubjects in ps8.py , which loads a list of subjects from a file. Each line of the file contains a string of the form “name,value,work”, where the name is a string, the value is an integer indicating how much a student learns by taking the subject, and the work is an integer indicating the number of hours a student must spend to pass the subject. loadSubjects should return a dictionary mapping subject names to tuples, where the tuples are pairs of (learning value, work hours) integers. def loadSubjects(filename): """ Returns a dictionary mapping subject name to (value, work), where the name is a string and the value and work are integers. The subject information is read from the file named by the string filename. Each line of the file contains a string of the form "name,value,work". returns: dictionary mapping subject name to (value, work) """ # The following sample code reads lines from the specified file and prin
Background image of page 2
# each one. inputFile =
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/12/2010 for the course EECS 6.00 taught by Professor Grimson during the Spring '08 term at MIT.

Page1 / 6

pset8 - MIT OpenCourseWare http:/ocw.mit.edu 6.00...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online