Prolog Time Overlap Woes <p>Say I have this Knowledge Base:</p> <pre><code>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))). </code></pre> <p>So, after a lot of effort, I managed to write something that prints the first person who has availability during a specific slot with the following code:</p> <pre><code>meetone(Person, slot(time(BeginHour, BeginMinute), time(EndHour, EndMinute))) :- free(Person, slot(time(BH, BM), time(EH, EM))), BH*60 + BM =&lt; EndHour*60 + EndMinute, EH*60 + EM &gt;= BeginHour*60 + BeginMinute. main :- (meetone(Person,slot(time(7,15),time(7,20))); halt), write(Person), nl, halt. :- initialization(main). </code></pre> <p>This prints bob, the expected result.</p> <p>Here's where it gets complicated (at least for me). Let's say I want to find out all the time slots everyone in the Knowledge Base has in common. The following code demonstrates how I ultimately want to call this:</p> <pre><code>people([ann,bob,carla]). meet :- ??? main :- (setof(Slot,meet(Slot),Slots); halt), write(Slots), nl, halt. :- initialization(main). </code></pre> <p>Here's some vague pseudocode that I think might accomplish what I'm looking for, but I'm not experienced enough to get it working.</p> <ol> <li>Start with the first person's free slots.</li> <li>Recursively traverse the rest of the list of people, finding the overlapping times.</li> <li>Slots can be verified to overlap using something similar to meetone; following this verification, the max of the two slot's begin times and the min of the two end times can be used to find the exact overlapping period.</li> <li>Print the final list of slots.</li> </ol> <p>The final output would show slots of 8:00 - 8:30 and 10:00 - 10:15. Any help in accomplishing this would be greatly appreciated.</p>