Before students can take a course at UNM, they must meet that course's prerequisite requirements. For example, in order to take MATH 1250 a student must have completed MATH 1220. However, some prerequisite requirements are more complicated than simply requiring a single course. They can be a logical combination of multiple courses, or even other logical combinations. For example, the prerequisite requirement for MATH 1512 looks like (MATH 1230 and MATH 1240) or MATH 1250
.
This problem consists of two parts:
- Write code that determines if a given course can be taken provided a list of courses that have already been completed. A course's prerequisite requirements can be read from the file
data/prerequisites.json
. See the section Course Prerequisite Data for details on how the data is formatted. Below is an example of the inputs and expected output for one scenario:
INPUTS:
COURSE: 'MATH 1512'
COMPLETED_COURSES: ['MATH 1215']
OUTPUT:
false
- Working off of your solution from part 1, modify your code to return a list of courses that will need to be completed in order to satisfy the given course's prerequisite requirements. Note - while there could be multiple correct solutions, be careful not to include more courses than necessary. Below is an example of the inputs and expected output for one scenario:
INPUTS:
COURSE: 'MATH 1512'
COMPLETED_COURSES: ['MATH 1215']
OUTPUT:
['MATH 1220', 'MATH 1250']
# In order to take MATH 1512, the student could complete MATH 1250 which requires MATH 1220, which requires MATH 1215.
- Fork this repository.
- Write your code to solve the two challenges listed above.
- Using your code, create an output file that produces solutions for the scenarios listed in the
data/tests.json
file. Details can be found in the Testing & Output File section below. - Create a file named INSTRUCTIONS that detail how to run your code.
- Commit and push your code.
- Create a pull request.
- You may use any programming language you'd like, though python or ruby are preferred.
- Refrain from using any external libraries or code.
- As cool as ChatGPT is, please don't use it to write code for you.
- If you have any questions about the problem definition or the data, feel free to contact us at [email protected]
In order to complete the above tasks, this repository includes a file,data/prerequisites.json
that contain prerequisite requirements for several courses. The root object contains keys that represent a course code, and the value is an object specifying that course's prerequisite requirements.
{
"MATH 1512": { ...requirementObject },
"MATH 1240": { ...requirementObject },
"MATH 100": null
...
}
Requirement objects come in three types:
- course: A course requirement indicates that a specific course (specified by the key code) must be completed in order to satisfy the requirement.
- and: An "and" requirement indicates that all sub requirements (specified by the key operands) must also be satisfied.
- or: An "or" requirement indicates that at least one sub-requirement (specified by the key operands) must be satisfied.
A course with null indicates that the course has no requirements and can always be taken.
Examples of the three requirement json objects can be seen below.
{
"type": "course",
"code": "MATH 1240"
}
{
"type": "and",
"operands": [ ... ] // Contains multiple requirement objects
}
{
"type": "or",
"operands": [ ... ] // Contains multiple requirement objects
}
Putting this all together, the prerequisite requirements of (MATH 1230 and MATH 1240) or MATH 1250
for the course MATH 1512 would look like:
{
"MATH 1512": {
"type": "or",
"operands": [
{
"type": "and",
"operands": [
{
"type": "course",
"code": "MATH 1230"
},
{
"type": "course",
"code": "MATH 1240"
}
]
},
{
"type": "course",
"code": "MATH 1250"
}
]
},
...
}
The file data/tests.json
contains a list of json objects that represent a scenario to evaluate. They also contain the expected solution to part 1. The objects look like:
[
{
"course": "MATH 1512", // The course to evaluate
"completedCourses": ["MATH 1250"], // Course that have already been completed
"isSatisfied": true // Some cases contain the expected solution to part 1 to serve as a guide
},
...
]
In order for us to evaluate the solutions your code produces, create a file called output.json
that contains your code's output for each test case formatted as follows:
[
{
"course": "MATH 1512", // The course that was evaluated - copied from the test data
"completedCourses": ["MATH 1215"], // The list of courses already completed - copied from the test data
"isSatisfied": true, // The output your code produced from part 1.
"coursesNeeded": [ ... ] // The output your code produced from part 2.
},
...
]