Question
You will write a program that checks a participant's proposed Convention schedule and determines 1) whether the proposed list of workshops is possible to attend,
You will write a program that checks a participant's proposed Convention schedule and determines 1) whether the proposed list of workshops is possible to attend, without any time conflicts, and 2) whether the proposed list contains at least 5 credits' worth of workshops, so that the attendee will earn a certificate.
A person's Convention schedule will be represented as a list of workshops, where each workshop entry contains these items:
A workshop number (a positive integer)
A day number (1, 2, or 3, indicating which day the workshop falls on)
A number of credits (1 or 2)
A start time, using a 24-hour clock
A stop time, using a 24-hour clock
All of these numbers are positive integers.
For example, the list
[2, 3, 1, 1200, 1315]
means that workshop 2 occurs on day 3 of the Convention, is worth 1 credit, begins at 12 noon, and ends at 1:15pm.
The exact format of the input and output will be slightly different for the four different languages, to make the input and output as easy as possible in each different language. The four input/output specifications for the four different languages are given below.
A time conflict is a pair of workshops that overlap in time; for example, [4, 1, 1, 1100, 1230] and [6, 1, 1, 1200, 1315] is a conflict, because both workshops are being held during the 12noon - 12:30pm time period. [4, 1, 1, 1100, 1230] and [6, 1, 1, 1230, 1315] is also a conflict, but [4, 1, 1, 1100, 1230] and [6, 1, 1, 1231, 1315] is not. Note that [4, 1, 1, 1100, 1230] and [8, 3, 1, 1200, 1315] is not a conflict, because these workshops occur on two different days.
There will be no more than 100 workshops in the Convention.
Write a Scheme program to solve the problem described above. Define a function (certificate Workshop_List) which takes a single parameter, Workshop_List, and returns #T or #F. Workshop_List is a list of 5-element lists containing
1)A workshop number (a positive integer)
2)A day number (1, 2, or 3)
3)A number of credits (1 or 2)
4)A start time (an integer in the range 0600-2300)
5)A stop time (an integer in the range 0600-2300)
The function should return #T if the list of workshops totals at least 5 credits and contains no time conflicts, and should return #F otherwise.
You may assume that list Workshop_List 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. The events in list Workshop_List are not necessarily sorted by workshop numbers, starting times, or any other order. In your program, you may write and call any additional functions that are helpful in the computation
THIS IS MY CURRENT CODE BUT IT DOES NOT WORK PLEASE FIX
(define (check_day w1 w2)
(eqv? (cadr w1) (cadr w2)))
(define (check_time w)
(cadr (cdr (cdr (cdr w)))))
(define (check_time2 w)
(cadr (cdr (cdr (cdr w)))))
(define (times_ok w1 w2)
(let ((start1 (check_time w1))
(start2 (check_time w2))
(end1 (check_time2 w1))
(end2 (check_time2 w2)))
(or (and (check_day w1 w2)
(or (and (>= start1 start2) (< start1 end2))
(and (< start1 start2) (>= end1 start2))))
(and (not (check_day w1 w2))
#t))))
(define (certificate Workshop_List)
(let ((total-credits 0)
(workshop-counts (make-vector 100 0)))
(for-each (lambda (workshop)
(vector-set! workshop-counts (car workshop) (+ (vector-ref workshop-counts (car workshop)) 1))
(set! total-credits (+ total-credits (caddr workshop))))
Workshop_List)
(and (>= total-credits 5)
(let ((no-conflicts #t))
(do ((i 0 (+ i 1)))
((or (>= i (- (length Workshop_List) 1)) (not no-conflicts)))
(do ((j (+ i 1) (+ j 1)))
((or (>= j (length Workshop_List)) (not no-conflicts)))
(if (and (> (vector-ref workshop-counts (car (list-ref Workshop_List i))) 0)
(> (vector-ref workshop-counts (car (list-ref Workshop_List j))) 0)
(times_ok (list-ref Workshop_List i) (list-ref Workshop_List j)))
(set! no-conflicts #f))))
no-conflicts))))
RUN TESTS ON THIS TO MAKE SURE IT WORKS CORRECTLY AND DISPLAYS THE CORRECT OUTPUT
Examples:
(certificate
'( (1 1 1 0930 1030)
(2 3 1 1200 1315)
(3 2 2 1400 1630)
(4 1 1 1100 1230)
(5 1 1 1545 1700) ) )
should return #T. Note that workshops 2 and 4 occur on different days, so there is no time conflict between them.
(certificate
'( (16 1 1 0930 1030)
(12 3 1 1200 1315)
(18 2 1 1400 1630)
(11 1 1 1100 1230)
(15 1 1 1545 1700)
(6 3 1 1400 1500)
(17 2 2 0800 1000) ) )
should return #T.
(certificate
'( (1 1 1 0930 1030)
(6 1 1 1200 1315)
(3 2 2 1400 1630)
(4 1 1 1100 1230)
(5 1 1 1545 1700) ) )
should return #F, because of the time conflict between workshops 6 and 4.
(certificate
'( (1 1 1 0930 1030)
(2 3 1 1200 1315)
(3 2 2 1400 1630) ) )
Step by Step Solution
There are 3 Steps involved in it
Step: 1
To address the issues with the given code and ensure it meets ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started