The Allegro Music School is preparing the program for its Spring Recital. The sc
ID: 3600556 • Letter: T
Question
The Allegro Music School is preparing the program for its Spring Recital. The school has two teachers, Ms. Smith and Mr. Jones, who teach students on a wide variety of instruments:
Brass instruments: trumpet, trombone, tuba
Woodwind instruments: flute, piccolo, clarinet, oboe
Keyboard instruments: organ, piano
String instruments: harp, violin, viola, cello
In the Spring Recital, the school wants to arrange the order of student performances to meet three criteria:
The teachers want to have the beginning students near the beginning of the recital, the intermediate students in the middle, and the advanced students at the end. Thus, the students will be in nondecreasing order according to the number of years they have been studying their instruments: 1st year students are followed by 2nd year students, and so on. Some years may be missing (i.e., it is possible to have no 2nd year students), but you may not have an advanced student followed by a beginner.
To ensure variety in the recital, there must not be two instruments from the same category next to each other in the recital order. That is, a brass player cannot be directly followed by another brass player, a keyboard player cannot be directly followed by another keyboard player, and so on.
Each of the teachers (Smith and Jones) should have at least two students in the recital.
For your homework, you will write a program that will take as input a proposed list of students, with their instruments, teachers, and years of study; your program must decide whether this list is an acceptable order for the recital.
Examples:
Example 1:
Example 2:
Example 3:
Example 4:
Example 5:
Write a Prolog program to solve the problem described above. Define a predicate recital_ok(+L) which takes a recital list L as a parameter; recital_ok should succeed if the recital list is acceptable, and should fail if the recital list is not acceptable.
Each element of list L will be a 4-element list containing a student name, followed by an instrument, followed by a teacher name, followed by the number of years of study for that student (an integer).
You may assume that list L will be in the correct format when the function is called; you do not have to error-check for a non-list or an incorrectly formed list. In your program, you may write and call any additional functions that are helpful in the computation.
For simplicity, assume further that each student's name, instrument, and teacher's name will start with a lower case letter.
In your program, you may write and call any additional predicates that are helpful in the computation.
For example,
should succeed, and
should fail.
Explanation / Answer
should succeed, and
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.