Question: Write and fully demonstrate a program that selects a set of acceptable meeting times for a set of people. Each person provides a set of
Write and fully demonstrate a program that selects a set of acceptable meeting times for a set of people. Each person provides a set of free time slots. For example: data.pl shows that Bob has two one-hour time slots that are free, one of which is 7:00AM8:30AM. When complete, this program will print a list of compatible meeting times for Ann, Bob, and Carla: 8:00AM8:30AM and 10:00AM10:15AM. Given two times slots, there are three ways in which they can overlap. Draw pictures. Youll need a rule for each way. Use the \== predicate to avoid zero-length meetings. Youll also need a predicate for comparing two times (e.g., lte).
data.pl
free(ann,slot(time(8,0),time(9,0))). free(ann,slot(time(10,0),time(11,0))).
free(bob,slot(time(7,0),time(8,30))). free(bob,slot(time(10,0),time(11,0))).
free(carla,slot(time(8,0),time(9,0))). free(carla,slot(time(10,0),time(10,15))).
free(dave,slot(time(8,0),time(9,0))). free(dave,slot(time(10,0),time(11,0))).
free(ed,slot(time(9,0),time(10,0))).
uniq.pl
notin(_, []). notin(V, [H|T]) :- V \= H, notin(V, T).
in(V, [H|_]) :- V=H. in(V, [_|T]) :- in(V, T).
set([]). set([H|T]) :- notin(H, T), set(T).
has([], _). has([H|T], L) :- in(H, L), has(T, L).
uniq(L, U) :- has(L, U), has(U, L), set(U).
meet.pl
#!/bin/gprolog --consult-file
:- include('data.pl'). :- include('uniq.pl').
% Your code goes here.
people([ann,bob,carla]).
main :- findall(Slot, meet(Slot), Slots), uniq(Slots, Uniq), write(Uniq), nl, halt.
:- initialization(main).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
